发布版本崩溃,而调试版本按预期运行

时间:2019-05-28 19:57:27

标签: android proguard

尝试在设备上运行发布版本时遇到以下异常。

   java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.IllegalStateException: com.google.android.gms.measurement.AppMeasurement#getInstance has been removed by Proguard. Add keep rule to prevent it.
            at android.app.ActivityThread.installProvider(ActivityThread.java:6419)
            at android.app.ActivityThread.installContentProviders(ActivityThread.java:5961)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5867)
            at android.app.ActivityThread.access$1100(ActivityThread.java:200)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1651)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6692)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
         Caused by: java.lang.IllegalStateException: com.google.android.gms.measurement.AppMeasurement#getInstance has been removed by Proguard. Add keep rule to prevent it.
            at com.google.firebase.FirebaseApp.zza(com.google.firebase:firebase-common@@16.0.1:766)
            at com.google.firebase.FirebaseApp.zze(com.google.firebase:firebase-common@@16.0.1:722)
            at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.1:329)
            at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.1:295)
            at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.1:282)
            at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.1:37)
            at android.content.ContentProvider.attachInfo(ContentProvider.java:1919)
            at android.content.ContentProvider.attachInfo(ContentProvider.java:1894)
            at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.1:31)
            at android.app.ActivityThread.installProvider(ActivityThread.java:6414)
            at android.app.ActivityThread.installContentProviders(ActivityThread.java:5961) 
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5867) 
            at android.app.ActivityThread.access$1100(ActivityThread.java:200) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1651) 
            at android.os.Handler.dispatchMessage(Handler.java:106) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:6692) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

我正在使用以下proguard配置

-keepclasseswithmembers class * {
    public static com.google.firebase.auth.FirebaseAuth getInstance();
}
-keep public class com.google.firebase.**
-keep public class com.google.firebase.auth.FirebaseAuth

-keep public class com.google.android.gms.measurement.**
-keep public class com.google.firebase.provider.FirebaseInitProvider

1 个答案:

答案 0 :(得分:1)

您需要在Pro-guard中添加几行:

#Firebase
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**

#GooglePlayServices
-keepnames class com.google.android.gms.** {*;}