android studio 3.1 Warning: The rule `-keep public

2019-03-09 16:06发布

i recently upgraded android studio but im not able to find the source of the following issue reported in android studio 3.1:

Warning: The rule `-keep public class *extends java.lang.annotation.Annotation {

enter image description here

enter image description here

the warning seems to be cut off perhaps and missing information. but it looks like a proguard issue although i am getting this warning when building debug variant. i checked my proguard files and i dont have a line that matches that exactly. i searched the entire project. any ideas on the root cause ?

8条回答
Rolldiameter
2楼-- · 2019-03-09 16:26
  1. open build.gradle file.
  2. remove “multiDexEnabled true”.
  3. rebuild app.
查看更多
来,给爷笑一个
3楼-- · 2019-03-09 16:31

This issue comes when you upload new upgrade version on google play store and after upload most users click on retain and then submit. Don't click on Retain just upload and submit. Your apk file uploaded successfully and Retain file automatically discard and set in deactivate mode.

Remember : Make sure your put all details of new update different to older version.

查看更多
混吃等死
4楼-- · 2019-03-09 16:33

class android.support.annotation.Keep is what I use (Android Studio 3.1.2) ...

-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}

there are further flags to control which annotations to keep:

-keepattributes RuntimeVisibleAnnotations
-keepattributes AnnotationDefault
-keepattributes *Annotation*

one can get the raw output by running ./gradlew assembleRelease in the terminal tab.

when nothing in the project's ProGuard configuration refers to Annotation, this warning might originate from the "consumer" rules of some referenced library, to be obfuscated at build time.

hence it appears to be a harmless warning, one can possibly mute it:

-dontwarn java.lang.annotation.Annotation
查看更多
疯言疯语
5楼-- · 2019-03-09 16:34

I removed the "multiDexEnabled true" from app's build gradle defaultConfig and the WARNING goes away:

defaultConfig {
    ...

    //multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "Xg"
}

good luck)

查看更多
趁早两清
6楼-- · 2019-03-09 16:35

Gradle version: 3.1.4

MultiDex: Enabled

In my case, I forgot to add translation for some string resources. No error/warning after adding.

查看更多
Explosion°爆炸
7楼-- · 2019-03-09 16:39

You are missing a space between the wildcard * and the keyword extends. The warning itself probably does not come from ProGuard but from the builtin shrinker of google.

If you can not find it in your project, then it is most likely a broken rule from a consumer Proguard file included in of the the dependent aar files.

查看更多
登录 后发表回答