Firebase库无法在< = Lolypop设备中运行

时间:2016-11-03 16:35:44

标签: android firebase firebase-cloud-messaging

在我目前的项目中,我使用FCM进行通知。它的优点和工作正常,但每当我尝试在低于lolypop的任何设备(即版本21)中打开应用程序时,它会在开始时崩溃。

我查了很多SO帖子,但从未见过有人将其修复为答案。

我使用下面的最新版本库

compile 'com.google.android.gms:play-services:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.firebase:firebase-core:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'

请帮助,我需要至少提供支持的软糖设备。

CRASH LOG:

FATAL EXCEPTION: main
 Process: com.arpaul.geocare, PID: 3127
 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.arpaul.geocare-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.arpaul.geocare-2, /vendor/lib, /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.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.arpaul.geocare-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.arpaul.geocare-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: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

1 个答案:

答案 0 :(得分:1)

您对com.google.android.gms:play-services:9.8.0的依赖包括所有Google Play服务API,其中大部分都是您不需要的。这不必要地增加了APK的大小和构建时间。它也可能导致应用程序有超过64K的方法引用,在旧设备上需要Multidex,explained here

相反,您应该删除com.google.android.gms:play-services:9.8.0的依赖项,并将其替换为您需要的特定API。标题为选择性地将API编译为可执行文件的部分中的说明为provided here