Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不幸的是,添加admob广告后,项目已停止_Android_Firebase_Admob - Fatal编程技术网

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);
    }
}