无法获取提供商com.google.firebase.provider.FirebaseInitProvider:由于此错误而运行项目。我该怎么办呢?请帮忙。
10-08 15:05:05.957 17562-17562/com.coretec.msacco E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.coretec.msacco, PID: 17562
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.coretec.msacco-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.coretec.msacco-2, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5055)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4626)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4566)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5336)
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:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.coretec.msacco-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.coretec.msacco-2, /vendor/lib, /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:5040)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4626)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4566)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5336)
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:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:5)
避免在gradle文件中使用play-services。 编译com.google.android.gms:play-services:9.8.0' 而是使用特定的 编译com.google.android.gms:play-services-location:9.8.0'
答案 1 :(得分:1)
为 multidex 配置您的应用
修改模块级 build.gradle 文件以启用 multidex 并添加 multidex 库作为依赖项,如下所示:
<块引用>android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
implementation "androidx.multidex:multidex:2.0.1"
}
根据您是否覆盖 Application 类,执行以下操作之一:
如果您不覆盖 Application 类,请编辑您的清单文件以在标签中设置 android:name,如下所示:
<块引用><?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="androidx.multidex.MultiDexApplication" >
...
</application>
</manifest>
如果您确实覆盖了 Application 类,请将其更改为扩展 MultiDexApplication(如果可能),如下所示:
<块引用>public class MyApplication extends MultiDexApplication { ... }
或者,如果您确实覆盖了 Application 类但无法更改基类,那么您可以覆盖 attachBaseContext() 方法并调用 MultiDex.install(this) 以启用 multidex:
> public class MyApplication extends SomeOtherApplication { @Override
> protected void attachBaseContext(Context base) {
> super.attachBaseContext(base);
> MultiDex.install(this); } }
注意:在 MultiDex.install() 完成之前,不要通过反射或 JNI 执行 MultiDex.install() 或任何其他代码。 Multidex 跟踪不会跟随这些调用,导致 ClassNotFoundException 或由于 DEX 文件之间的类分区错误而导致验证错误。