使用混淆器时构建期间的 GMS 错误

GMS Error during build while using proguard

当我尝试使用混淆器构建我的项目时,我在预验证时收到以下错误。

Preverifying...
Unexpected error while performing partial evaluation:
  Class       = [com/google/android/gms/internal/zzmz]
  Method      = [zza(Lcom/google/android/gms/internal/zzmh;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/google/android/gms/internal/zzne;Lcom/google/android/gms/internal/zzgf;Lcom/google/android/gms/internal/zzmy;)Lcom/google/android/gms/internal/zzmk;]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [com/google/android/gms/internal/zzmk] (with 1 known super classes) and [java/lang/String] (with 2 known super classes))
Unexpected error while preverifying:
  Class       = [com/google/android/gms/internal/zzmz]
  Method      = [zza(Lcom/google/android/gms/internal/zzmh;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/google/android/gms/internal/zzne;Lcom/google/android/gms/internal/zzgf;Lcom/google/android/gms/internal/zzmy;)Lcom/google/android/gms/internal/zzmk;]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [com/google/android/gms/internal/zzmk] (with 1 known super classes) and [java/lang/String] (with 2 known super classes))
Warning: Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: Can't find common super class of [com/google/android/gms/internal/zzmk] (with 1 known super classes) and [java/lang/String] (with 2 known super classes)

我在混淆器中添加了以下内容,其他库也有其他规则。

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.facebook.ads.** { *; }
-dontwarn com.google.android.gms.ads.**

我的 gradle.build 有以下库

implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:preference-v7:$rootProject.supportLibraryVersion"
    implementation "com.android.support:design:$rootProject.supportLibraryVersion"
    implementation "com.android.support:palette-v7:$rootProject.supportLibraryVersion"
    implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
    implementation "android.arch.persistence.room:rxjava2:$rootProject.roomVersion"
    //ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:$rootProject.lifecycleVersion"
    implementation "android.arch.work:work-runtime:$rootProject.workManagerVersion"
    implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
    implementation "com.jakewharton.timber:timber:$rootProject.timberVersion"
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.interceptorVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rx2AndroidVersion"
    implementation "io.reactivex.rxjava2:rxjava:$rootProject.rx2AndroidVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
    implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    implementation "com.android.billingclient:billing:$rootProject.billingVersion"
    implementation "com.facebook.android:audience-network-sdk:$rootProject.facebookAds"
    implementation ("com.google.android.gms:play-services-places:$rootProject.gPlacesVersion"){
        exclude module: 'play-services-ads'
    }
    implementation ("com.google.android.gms:play-services-location:$rootProject.gLocationVersion") {
        exclude module: 'play-services-ads'
    }
    implementation 'com.android.support:multidex:1.0.3'

    implementation "com.google.firebase:firebase-core:$rootProject.firebaseCore"
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
//    implementation "com.google.firebase:firebase-config:$rootProject.firebaseConfig"
    implementation "com.google.firebase:firebase-perf:$rootProject.firebasePerf"

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$rootProject.lifecycleVersion"
    annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
    annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    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'

    debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'

根据 Google Play 服务设置站点,无需向混淆器添加任何内容,当我从混淆器中删除 gms 规则时,会得到一长串这样的警告

Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced class com.google.android.gms.common.internal.zzf$zzb
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced class com.google.android.gms.common.internal.zzf$zzc
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced class com.google.android.gms.internal.zzaf
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced class com.google.android.gms.internal.zzaf$zza
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced class com.google.android.gms.internal.zzaf$zza
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced method 'void disconnect()' in program class com.google.android.gms.internal.zzapu
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced method 'boolean isConnected()' in program class com.google.android.gms.internal.zzapu
Warning: com.google.android.gms.internal.zzapt$zza: can't find referenced method 'boolean isConnecting()' in program class com.google.android.gms.internal.zzapu

警告列表继续。如果需要,我可以添加其余的混淆规则。 根据 Firebase 网站,我使用的 Google Play 服务是 4.1.0,我的 Firebase 库是最新的。使用版本 15.0.1(最新)Google 播放 Google 播放位置和位置

Proguard Output

除了 com.google.android.gms.internal.*(即:Google Services)的规则外,您还缺少很多规则。 manual 解释了所有这些建议;虽然我仍然可以举个例子,但是 class:

-verbose
-keep,includedescriptorclasses class com.google.android.gms.internal.** { *; }
-keep class com.google.android.gms.internal.** {com.google.android.gms.internal.** initialize(android.content.Context);}
# -dontnote com.google.android.gms.internal.**
# -dontwarn com.google.android.gms.internal.**

刚刚注释掉 dontnotedontwarn,因为在开发规则集时更容易收到所有通知。添加修饰符 includedescriptorclasses 应该至少减少几行抱怨,而你必须定义规则,直到没有更多的抱怨。这是一个漫长而麻烦的过程,没有任何默认配方 - 提供可靠的规则是完全不可能的,同时不能使用 trial & error.

的方法