Search code examples
androidadmobclassnotfoundexception

AdMob causing: unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException


Im trying to implement adMob but my app isn't launching and providing the following error:

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider" on path: DexPathList[[zip file "/data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/base.apk"],nativeLibraryDirectories=[/data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/lib/arm64, /system/lib64]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:7369)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6909)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6826)
    at android.app.ActivityThread.access$1400(ActivityThread.java:267)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1981)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:7762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider" on path: DexPathList[[zip file "/data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/base.apk"],nativeLibraryDirectories=[/data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/lib/arm64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7353)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6909) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6826) 
    at android.app.ActivityThread.access$1400(ActivityThread.java:267) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1981) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:237) 
    at android.app.ActivityThread.main(ActivityThread.java:7762) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047) 
    Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/base.apk because: Bad encoded_array value: Failure to verify dex file '/data/app/com.aaron.derrystudios.wordresolver-mOF2EngPcA5nT8dd27zx5g==/base.apk': Bad encoded_value method type size 7
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:365)
    at dalvik.system.DexFile.<init>(DexFile.java:107)
    at dalvik.system.DexFile.<init>(DexFile.java:80)
    at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
    at dalvik.system.DexPathList.makeDexElements(DexPathList.java:403)
    at dalvik.system.DexPathList.<init>(DexPathList.java:164)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
    at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
    at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:892)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:991)
    at android.app.LoadedApk.getResources(LoadedApk.java:1248)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2614)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2606)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6724)
            ... 8 more

I searched for this problem and all of the solutions, like this, are saying you now need to provide the App ID supplied from adMob in the manifest. I have tripled checked this and the correct app ID is provided in the manifest under meta-data tags as you can see here:

appdid

I've been following this official guide and went over it twice, but I am still getting this error.

I am also using a dedicated test ad unit ID for Android banners, so I don't think that is the problem.

What else could be causing this?


Solution

  • I got a similar error and this solved it.

    In biuld.gradle (Module) 
    android { 
     ...
     compileOptions {
      sourceCompatibility = 1.8
      targetCompatibility = 1.8
     }
    }