java.lang.ClassNotFoundException: Didn't find class “com.google.android.gms.ads.MobileAdsInitProvider”

后端 未结 5 1548
旧时难觅i
旧时难觅i 2020-12-17 21:33

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 f

相关标签:
5条回答
  • 2020-12-17 22:06
    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'

    0 讨论(0)
  • 2020-12-17 22:09

    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 讨论(0)
  • 2020-12-17 22:14

    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

    0 讨论(0)
  • 2020-12-17 22:24

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

    0 讨论(0)
  • 2020-12-17 22:27

    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.

    0 讨论(0)
提交回复
热议问题