46

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 ?

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • 1
    I'm facing the same issue here, I would guess it is a new "broken" code from third party library. I just updated a couple of libs here so I don't the slightest idea which lib is messing around. I agree with Moonbloom, someone forgot to added a space after "extends", but it is not your fault ;) – Agna JirKon Rx Mar 27 '18 at 18:42
  • JFYI I just updated android.suport, facebook.sdk, retrofit and picasso - and this very issue appeared – Agna JirKon Rx Mar 27 '18 at 18:43
  • 4
    It's bug in android gradle plugin https://issuetracker.google.com/issues/72080964 – arcone1 Mar 29 '18 at 09:31
  • 2
    This issue has been resolved as of Apr 6, 2018 according to [Google Issue Tracker](https://issuetracker.google.com/issues/72080964). – Vincent Mattana Apr 09 '18 at 07:51
  • 2
    Confirmed, warning removed in 3.2.0-alpha12 – random Apr 26 '18 at 11:57

11 Answers11

23

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!

Aba
  • 2,307
  • 2
  • 18
  • 32
  • side note: Simply installing AS 3.2 is not enough. You may need to update the gradle plugin to 4.6 & android build gradle to 3.2.0. – Aba Sep 25 '18 at 03:16
17

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.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
11

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

mridul
  • 1,986
  • 9
  • 29
  • 50
3

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

defaultConfig {
    ...

    //multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "Xg"
}

good luck)

Hovanes Mosoyan
  • 760
  • 7
  • 10
3

Class android.support.annotation.Keep is what I use
(which is now being called androidx.annotation.Keep).

-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
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
2
  1. open build.gradle file.
  2. remove “multiDexEnabled true”.
  3. rebuild app.
Ahamadullah Saikat
  • 4,437
  • 42
  • 39
0

Gradle version: 3.1.4

MultiDex: Enabled

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

activesince93
  • 1,716
  • 17
  • 37
0

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.

Pradeep Sheoran
  • 493
  • 6
  • 15
0

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

joeabala
  • 266
  • 3
  • 11
0

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

version choose according to your app compat version

0

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

Wojtek Dmyszewicz
  • 4,188
  • 5
  • 30
  • 42