13

I am facing this issue in Android Version 4.4 and below. I have integrated Google admob and when I run the app, the app crashes with ClassNotFoundException.

Please find the stacktrace below.

Process: app.learnkannada.com.learnkannadakannadakali, PID: 1320
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/app.learnkannada.com.learnkannadakannadakali-2.apk"],nativeLibraryDirectories=[/data/app-lib/app.learnkannada.com.learnkannadakannadakali-2, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.MobileAdsInitProvider" on path: DexPathList[[zip file "/data/app/app.learnkannada.com.learnkannadakannadakali-2.apk"],nativeLibraryDirectories=[/data/app-lib/app.learnkannada.com.learnkannadakannadakali-2, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:4778)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5017) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    at dalvik.system.NativeStart.main(Native Method) 

I have tried looking on google but couldn't find this problem. Requesting the community to please help on this.

Note: Please note that I have already added mobile ads meta-data in Android Manifest already.

2
  • 1
    have you find any solution.. i m facing the same problem
    – Raza
    Commented Jan 22, 2019 at 9:52
  • I'm also facing this problem. SDKs above 5 work properly. But not below... please anyone help us to find a solution.... Commented Sep 14, 2019 at 15:02

5 Answers 5

52

You are getting this error because you have use multiDex but some implementation part is missing. Follow below steps to resolve the error.

1) Add "multiDexEnabled true" in defaultconfig in app-level gradle file

android {
    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 28
        multiDexEnabled true
    }
    ...
}

2) If your minSdkVersion is less than 21 then add below dependency.

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

3) Use MultiDexApplication class as Application class. There are three way to use MultiDexApplication as Application class

i) Just set MultiDexApplication class in AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

ii) If you are already using custom application class then extent MultiDexApplication in custom application class

public class MyApplication extends MultiDexApplication { ... }

iii) If it is not possible to extend MultiDexApplication because you already extend other class and can not change it then use below method in your custom application class

public class MyApplication extends SomeOtherApplication {
  @Override
  protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
  }
}

Note: I was facing same error and just solved by extending MultiDexApplication class

5
  • Thank you. Had tried the same solution and it worked. Please upvote the question, if you think it's a valid one.
    – Varun A M
    Commented Feb 5, 2019 at 8:28
  • 2
    I tried all the step that you have mention above Still i am getting crash with same error. Commented Feb 23, 2019 at 13:21
  • So, I did all the steps and still getting the same error. I would try to extend MultiDexApplication class, but I can't as I extend there another class... Please help.... P.S. setting it in Manifest file, ...multidex.MultiDexApplication is as unresolved, no idea why.... Commented Sep 17, 2019 at 19:53
  • I found the problem, I just needed to paste the MultiDex into BaseContext. Commented Sep 18, 2019 at 19:47
  • you sir are a legend. thank you! Feels great to be able to support legacy ;) Commented May 28, 2020 at 0:25
3

I just did the 'Build' > 'Clean Project' and it works.

2
  1. First make multiDexEnable ture in android defaultConfig

    android {
        defaultConfig {
           minSdkVersion 14
           targetSdkVersion 22
           multiDexEnabled true
        }
    }
    
  2. Add this in dependency if your minSdkVersion is less then 21.

    implementation 'com.android.support:multidex:1.0.3'

2

I was having this error message as well. In my case it nothing to do with multidex, but with compatibility javaversion.

File >> Project Structure >> Modules >> app >> Properties Change "Source Compatibility" and "Target Compatibility" to 1.8 (currently).

Or in build.gradle in "Module: app" (Not under Project.)

android { 
    ...
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

All credit to lazybug: Failed to verify dex: Bad method handle type 7

0

I got a similar error and this solved it.

android { 
    ...
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

I didn't comment in the place posted by Majid Mohammad above, so I added an answer.

Not the answer you're looking for? Browse other questions tagged or ask your own question.