Proguard - Can't find common super class of [com/google/android/gms/d/kl]

吃可爱长大的小学妹 提交于 2019-11-28 11:14:56

问题


I am failing to create a release build. Suddenly Android Studio started throwing below error.

Unexpected error while performing partial evaluation:
  Class       = [com/google/android/gms/d/lc]
  Method      = [a(Lcom/google/android/gms/d/kk;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/google/android/gms/d/lh;Lcom/google/android/gms/d/en;Lcom/google/android/gms/d/lb;)Lcom/google/android/gms/d/kn;]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [com/google/android/gms/d/kn] (with 1 known super classes) and [java/lang/String] (with 2 known super classes))
Unexpected error while preverifying:
  Class       = [com/google/android/gms/d/lc]
  Method      = [a(Lcom/google/android/gms/d/kk;Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/google/android/gms/d/lh;Lcom/google/android/gms/d/en;Lcom/google/android/gms/d/lb;)Lcom/google/android/gms/d/kn;]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [com/google/android/gms/d/kn] (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/d/kn] (with 1 known super classes) and [java/lang/String] (with 2 known super classes)

Here is my Proguard Configurations

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

-keep class com.facebook.ads.** { *; }

Here is the list of gradle dependencies of my project

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.google.firebase:firebase-perf:16.0.0'
    implementation 'com.google.firebase:firebase-config:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.android.gms:play-services-analytics:16.0.0'
    implementation 'com.google.android.gms:play-services-drive:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.startapp:inapp-sdk:3.8.4'
    implementation 'com.facebook.android:audience-network-sdk:4.28.2'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.7.1'
    testImplementation 'org.powermock:powermock-mockito-release-full:1.4.9'   
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }
}

Note Commenting the Facebook audience network dependency fixes the error. Unfortunately I cannot do it permanently from the project.

Please help me identifying the cause of an issue. Thanks in advance.


回答1:


Finally I managed to fix the error. As I am not Proguard expert, I may be wrong but this is the workaround I see at the moment.

As I have mentioned in the question, Facebook Audience Network causes the problem with the release build and errors are associated with the GMS Play Service library. According to comment posted by @pedrofsn, Facebook Audience Network uses the Google Play Service Ads library.

I started looking into documentation for the error Can't find common super class of. It says that

A class in one of your program jars or library jars is referring to a class or interface that is missing from the input. The warning lists both the referencing class(es) and the missing referenced class(es). There can be a few reasons, with their own solutions:

As it says the warning lists both the referencing class(es) and the missing referenced class(es), I decided to remove dontwarn just to see the warnings by the Proguard & updated my Proguard Configuration as below

-keep public class com.google.android.gms.* { public *; }

-keep class com.facebook.ads.** { *; }

I managed to see all the warnings by Proguard as the screenshot below.

As we can see from the screenshot, google ads library classes cannot find their referenced class com.google.android.gms.common.internal.zzac. My guess is that this class com.google.android.gms.common.internal.zzac should belong to the internal jar of the google ads dependency & that internal jar is probably missing.

So I have manually added the google ads dependency to my app level build.gradle as below

implementation 'com.google.android.gms:play-services-ads:15.0.1' 

And I see I can compile the release build successfully.




回答2:


I fixed downgrading 'com.google.firebase:firebase-messaging:17.0.0' to 'com.google.firebase:firebase-messaging:15.0.2'




回答3:


For this to work, I had to uncomment:

buildTypes {
    release {
        //minifyEnabled true
        //shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

and add the below to your proguard-rules.pro file:

-keep class com.google.android.gms.internal.** { *; }
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

although uncommenting minifyEnabled is not recommended since it removes dead/unused code



来源:https://stackoverflow.com/questions/50583150/proguard-cant-find-common-super-class-of-com-google-android-gms-d-kl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!