带有 ProGuard 的 Firebase
Posted
技术标签:
【中文标题】带有 ProGuard 的 Firebase【英文标题】:Firebase with ProGuard 【发布时间】:2019-02-13 18:18:30 【问题描述】:我正在使用 firebase 制作一个应用程序,它运行良好。 直到我打开 ProGuard 甚至 R8。
我基本上尝试了我在互联网上找到的所有 ProGuard 规则组合,我什至尝试过
-keep class com.firebase.** *;
-keep class mypackage.** *;
我有完全相同的项目,只是代码结构不同,它确实可以完美地使用以下规则:
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keepattributes Signature
-keepclassmembers class com.tritrio.anabi2y.model.** *;
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$**
**[] $VALUES;
public *;
-dontwarn com.firebase.ui.auth.**
这里是 StackTrace:
2018-09-08 21:00:03.471 9889-9963/com.tritrio.anabi2y E/io.grpc.a.J: Creating atomic field updaters failed
java.lang.RuntimeException: java.security.PrivilegedActionException: java.lang.NoSuchFieldException: No field streamClosed in class Lio/grpc/a/J$c; (declaration of 'io.grpc.a.J$c' appears in /data/app/com.tritrio.anabi2y-1/base.apk:classes2.dex)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.<init>(AtomicIntegerFieldUpdater.java:380)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater(AtomicIntegerFieldUpdater.java:58)
at io.grpc.a.J.<clinit>(CensusTracingModule.java:77)
at io.grpc.a.c.c(AbstractManagedChannelImplBuilder.java:420)
at io.grpc.a.c.a(AbstractManagedChannelImplBuilder.java:395)
at com.google.firebase.firestore.f.e.<init>(com.google.firebase:firebase-firestore@@17.0.5:102)
at com.google.firebase.firestore.b.w.a(com.google.firebase:firebase-firestore@@17.0.5:1217)
at com.google.firebase.firestore.b.y.run(com.google.firebase:firebase-firestore@@17.0.5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.g.c$a.run(com.google.firebase:firebase-firestore@@17.0.5:190)
at java.lang.Thread.run(Thread.java:760)
Caused by: java.security.PrivilegedActionException: java.lang.NoSuchFieldException: No field streamClosed in class Lio/grpc/a/J$c; (declaration of 'io.grpc.a.J$c' appears in /data/app/com.tritrio.anabi2y-1/base.apk:classes2.dex)
at java.security.AccessController.doPrivileged(AccessController.java:71)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.<init>(AtomicIntegerFieldUpdater.java:358)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater(AtomicIntegerFieldUpdater.java:58)
at io.grpc.a.J.<clinit>(CensusTracingModule.java:77)
at io.grpc.a.c.c(AbstractManagedChannelImplBuilder.java:420)
at io.grpc.a.c.a(AbstractManagedChannelImplBuilder.java:395)
at com.google.firebase.firestore.f.e.<init>(com.google.firebase:firebase-firestore@@17.0.5:102)
at com.google.firebase.firestore.b.w.a(com.google.firebase:firebase-firestore@@17.0.5:1217)
at com.google.firebase.firestore.b.y.run(com.google.firebase:firebase-firestore@@17.0.5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.g.c$a.run(com.google.firebase:firebase-firestore@@17.0.5:190)
at java.lang.Thread.run(Thread.java:760)
Caused by: java.lang.NoSuchFieldException: No field streamClosed in class Lio/grpc/a/J$c; (declaration of 'io.grpc.a.J$c' appears in /data/app/com.tritrio.anabi2y-1/base.apk:classes2.dex)
at java.lang.Class.getDeclaredField(Native Method)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl$1.run(AtomicIntegerFieldUpdater.java:361)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl$1.run(AtomicIntegerFieldUpdater.java:360)
at java.security.AccessController.doPrivileged(AccessController.java:67)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater$AtomicIntegerFieldUpdaterImpl.<init>(AtomicIntegerFieldUpdater.java:358)
at java.util.concurrent.atomic.AtomicIntegerFieldUpdater.newUpdater(AtomicIntegerFieldUpdater.java:58)
at io.grpc.a.J.<clinit>(CensusTracingModule.java:77)
at io.grpc.a.c.c(AbstractManagedChannelImplBuilder.java:420)
at io.grpc.a.c.a(AbstractManagedChannelImplBuilder.java:395)
at com.google.firebase.firestore.f.e.<init>(com.google.firebase:firebase-firestore@@17.0.5:102)
at com.google.firebase.firestore.b.w.a(com.google.firebase:firebase-firestore@@17.0.5:1217)
at com.google.firebase.firestore.b.y.run(com.google.firebase:firebase-firestore@@17.0.5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.g.c$a.run(com.google.firebase:firebase-firestore@@17.0.5:190)
at java.lang.Thread.run(Thread.java:760)
2018-09-08 21:00:03.743 9889-9922/com.tritrio.anabi2y E/Fabric: Failed to retrieve settings from https://settings.crashlytics.com/spi/v2/platforms/android/apps/com.tritrio.anabi2y/settings
2018-09-08 21:00:03.745 9889-9930/com.tritrio.anabi2y E/Answers: Failed to retrieve settings
2018-09-08 21:00:03.766 9889-9889/com.tritrio.anabi2y E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tritrio.anabi2y, PID: 9889
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
at com.google.firebase.firestore.g.c.a(com.google.firebase:firebase-firestore@@17.0.5:324)
at com.google.firebase.firestore.g.f.run(com.google.firebase:firebase-firestore@@17.0.5)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6375)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
Caused by: java.lang.AbstractMethodError: abstract method "com.google.protobuf.y$d com.google.protobuf.y$d.a(int)"
at com.google.protobuf.t.a(GeneratedMessageLite.java:1319)
at b.a.c.a.F$b.a(com.google.firebase:firebase-firestore@@17.0.5:2145)
at b.a.c.a.F$b$a.a(com.google.firebase:firebase-firestore@@17.0.5:428)
at com.google.firebase.firestore.f.p.a(com.google.firebase:firebase-firestore@@17.0.5:665)
at com.google.firebase.firestore.c.N.a(com.google.firebase:firebase-firestore@@17.0.5:150)
at com.google.firebase.firestore.c.w.b(com.google.firebase:firebase-firestore@@17.0.5:82)
at com.google.firebase.firestore.c.O.a(com.google.firebase:firebase-firestore@@17.0.5:479)
at com.google.firebase.firestore.c.V.run(com.google.firebase:firebase-firestore@@17.0.5)
at com.google.firebase.firestore.c.u.a(com.google.firebase:firebase-firestore@@17.0.5:117)
at com.google.firebase.firestore.c.O.a(com.google.firebase:firebase-firestore@@17.0.5:474)
at com.google.firebase.firestore.b.f.a(com.google.firebase:firebase-firestore@@17.0.5:165)
at com.google.firebase.firestore.b.t.a(com.google.firebase:firebase-firestore@@17.0.5:79)
at com.google.firebase.firestore.b.w.c(com.google.firebase:firebase-firestore@@17.0.5:132)
at com.google.firebase.firestore.b.C.run(com.google.firebase:firebase-firestore@@17.0.5)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.g.c$a.run(com.google.firebase:firebase-firestore@@17.0.5:190)
at java.lang.Thread.run(Thread.java:760)
这是我项目的 build.gradle:
buildscript
ext.kotlin_version = '1.2.61'
repositories
google()
jcenter()
maven url 'https://maven.fabric.io/public'
dependencies
classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.1'
classpath 'io.fabric.tools:gradle:1.25.4'
allprojects
repositories
google()
jcenter()
task clean(type: Delete)
delete rootProject.buildDir
这是我的模块的 build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'
android
compileSdkVersion 28
defaultConfig
applicationId "com.tritrio.anabi2y"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// multiDexEnabled true
resConfigs "en", "ar"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debug
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.support:appcompat-v7:28.0.0-alpha3"
implementation "com.android.support:support-v4:28.0.0-alpha3"
implementation "com.android.support:recyclerview-v7:28.0.0-alpha3"
implementation "com.android.support:cardview-v7:28.0.0-alpha3"
implementation "com.android.support:design:28.0.0-alpha3"
implementation "com.android.support:customtabs:28.0.0-alpha3"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation "com.google.firebase:firebase-core:16.0.3"
implementation "com.google.firebase:firebase-auth:16.0.3"
implementation "com.firebaseui:firebase-ui-auth:4.1.0"
// implementation "com.facebook.android:facebook-login:4.35.0"
implementation "com.google.android.gms:play-services-auth:16.0.0"
implementation "com.google.firebase:firebase-firestore:17.1.0"
implementation "com.firebaseui:firebase-ui-firestore:4.1.0"
implementation "android.arch.paging:runtime:1.0.1"
implementation "com.github.bumptech.glide:glide:4.8.0"
// implementation 'com.android.support:multidex:1.0.3'
implementation "com.google.firebase:firebase-storage:16.0.2"
implementation "com.crashlytics.sdk.android:crashlytics:2.9.5"
implementation "org.jsoup:jsoup:1.11.3"
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.maps.android:android-maps-utils:0.5'
kapt "android.arch.lifecycle:compiler:1.1.1"
kapt "com.github.bumptech.glide:compiler:4.8.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
【参考方案1】:R8 是罪魁祸首。
禁用后一切正常。
我已将问题报告给 google 和 firebase。
【讨论】:
救命!我花了几个小时在这个【参考方案2】:你应该使用官方Quickstart Samples中的规则
这些通常是 firebase android 库的规则
-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.** *;
-keepclassmembers class org.xmlpull.** *;
【讨论】:
我已经发布了解决方案。我试过了,没用,谢谢解答。以上是关于带有 ProGuard 的 Firebase的主要内容,如果未能解决你的问题,请参考以下文章
带有自定义控件和自定义 StringProperty 的 Proguard