java.lang.ClassNotFoundException: Didn#39;t find class quot;com.google.android.gms.ads.MobileAdsInitProviderquot;(java.lang.ClassNotFoundException:找不到类“com.google.android.gms.ads.MobileAdsInitProvider)
问题描述
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.
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
这篇关于java.lang.ClassNotFoundException:找不到类“com.google.android.gms.ads.MobileAdsInitProvider"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java.lang.ClassNotFoundException:找不到类“com.google.android.gms.ads.MobileAdsInitProvider"
基础教程推荐
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01