Android 不幸的是,添加admob广告后,项目已停止
这是我的应用程序构建渐变代码Android 不幸的是,添加admob广告后,项目已停止,android,firebase,admob,Android,Firebase,Admob,这是我的应用程序构建渐变代码 apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "24.0.2" defaultConfig { applicationId "com.example.personal.numbermania" minSdkVersion 10 targetSdkVersion 24 versionCode 1
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.personal.numbermania"
minSdkVersion 10
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "4g" //Here stablished how many cores you want to use your android studi 4g = 4 cores
}
buildTypes {
debug
{
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
}
这是我的项目构建gradle
//顶级生成文件,您可以在其中添加所有子项目/模块通用的配置选项
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
}
}
下面是我在调用AdView之前运行初始化时的错误
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
//replace your ID
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
更多详细信息请参见编译代码后,您拥有中每个类的
.class
文件
你的节目。这些文件包括Java用来解释和运行程序的字节码。
JVM试图找到.class
文件,但找不到该文件,导致运行时错误,NoClassDefError
将以下代码添加到build.gradle
文件修复了此问题:
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
调试/解决此问题需要尝试的其他方法
方法1:
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
- 将Google Play Services从Android SDK管理器更新至第30版
- 将
添加到依赖项中,或者删除com.android.support.multidex:1.0.1
(如果不需要)multiDexEnabled true
- 将属性-
添加到android:name=“android.support.multidex.MultiDexApplication”
AndroidManifest
AndroidManifest
已经定义了自定义应用程序类,请扩展MultiDexApplication
,而不是application
方法2:
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
更新应用程序
类的另一种方法:
public class App extends Application {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
...
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
方法3:
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
如果方法1和方法2不成功,请尝试将您的Google Play服务依赖关系降级为
8.4.0
发布您的活动代码adView adView=(adView)FindView wById(R.id.adView);AdRequest AdRequest=新建AdRequest.Builder().build();adView.loadAd(adRequest);你试过这个吗?初始化MobileAds的地方。?我还没有添加那一行。我应该添加吗?什么是firebase选项?公共类应用程序扩展应用程序{@Override protected void attachBaseContext(Context base){super.attachBaseContext(base);MultiDex.install(this);}给我你的邮件id。让我们在邮件中讨论一下你把它和你的main活动一起放在创建方法中吗?
public class App extends Application {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
...
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}