我正在尝试从API级别28(compileSdkVersion 28)的源代码编译.apk.该应用程序编译正常,但安装后崩溃.我的应用在界面本身的各个页面上都有Admob广告.
这是我的项目级别的build.gradle-
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
这是我的应用程序级别的build.gradle-
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 28
defaultConfig {
applicationId "****APP_ID****"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-ads:17.2.1'
implementation 'com.android.support:customtabs:27.0.2'
implementation 'com.google.android.gms:play-services-maps:+'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
}
apply plugin: 'com.google.gms.google-services'
这是我的AndroidManifest.xml中的广告代码-
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="*****ADMOB-ID*****"/>
</application>
这是我MainActivity.java中的广告代码
import com.google.android.gms.ads.MobileAds;
public class MainActivity extends Activity {
private LinearLayout linear1;
private AdView adview1;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.main);
initialize(_savedInstanceState);
initializeLogic();
MobileAds.initialize(this, "*****ADMOB-ID*****");
}
我是Android编码的新手.可能是什么问题?
解决方法:
您必须替换您的应用程序ID
defaultConfig {
applicationId "****APP_ID****"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
您必须添加版本
implementation 'com.google.android.gms:play-services-maps:+'
您必须在此处添加admob应用ID
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="*****ADMOB-ID*****"/>
</application>
和这里
MobileAds.initialize(this, "*****ADMOB-ID*****");
首先尝试修复这些错误