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

时光怂恿深爱的人放手 提交于 2019-12-02 17:25:15

As mentioned in the question's comments by @arcone1, @Vincent Mattana & confirmed by @random, the issue is resolved in Android Studio 3.2.

From the issue in Google Issue Tracker:

To clarify, this is a warning, not an error, from R8, which we use to compute the list of classes for the main dex, in legacy multidex variant. It does not affect the output, and it should not cause build nor runtime failures.
I am working on a fix to change this keep rule to "-keep public class * implements java.lang.annotation.Annotation", which is semantically the same, and removes the warning.

So, just ignore it for now or go bleeding edge with Canary (tread at your own risk).

UPDATE: 3.2 is out!

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.

I got same issue because of "multiDexEnabled true" setting in gradle defaultConfig.

I resolved this issue by adding multidex dependency "implementation 'com.android.support:multidex:1.0.3'"

android {
defaultConfig {
    ...
    multiDexEnabled true
}
...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

Reference : https://developer.android.com/studio/build/multidex

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

defaultConfig {
    ...

    //multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "Xg"
}

good luck)

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
  1. open build.gradle file.
  2. remove “multiDexEnabled true”.
  3. rebuild app.

Gradle version: 3.1.4

MultiDex: Enabled

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

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.

My gradle version was the issue i upgraded to com.android.tools.build:gradle:3.3.2 and the error disappeared.

used implementation 'com.android.support:support-annotations:27.1.1' in app dependancy

version choose according to your app compat version

In my case the warning appeared after changing Gradle version. Once I invalidated cache & restarted Android Studio the warning disappeared.

From the menu: File > Invalidate caches & restart

invalidate caches & restart

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