Home » Android » Android Build Error: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive

Android Build Error: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m facing this error when trying to build the app in release mode.

Error: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive

My proguard-rules.pro line looks like this:

-keepattributes Signature

what InnerClasses is the compiler referring to? What am I omitting?

How to&Answers:

Signature (Java 8 or higher) works only Java 8 or higher and InnerClasses (Java 5 or higher) so check your Android Studio is using Java SDK version.
Please update your Proguard config with below settings

Add this line to your proguard-rules.pro file:

-keepattributes InnerClasses

InnerClasses (Java 5 or higher)

Specifies the relationship between a class and its inner classes and
outer classes. Other than this and the naming convention with a ‘$’
separator between the names of inner classes and outer classes, inner
classes are just like ordinary classes. Compilers may need this
information to find classes referenced in a compiled library. Code may
access this information by reflection, for instance to derive the
simple name of the class.

Signature (Java 8 or higher)

Specifies the generic signature of the class, field, or method.
Compilers may need this information to properly compile classes that
use generic types from compiled libraries. Code may access this
signature by reflection.

More details about -keepattributes and more settings you can apply, please see below link.

Proguard options

Answer:

Ref : https://stuff.mit.edu/afs/sipb/project/android/sdk/android-sdk-linux/tools/proguard/docs/index.html#manual/usage.html

keepattributes [attribute_filter]

Specifies any optional attributes to be preserved. The attributes can
be specified with one or more -keepattributes directives. The optional
filter is a comma-separated list of attribute names. Attribute names
can contain ?, *, and ** wildcards, and they can be preceded by the !
negator. Typical optional attributes are Exceptions, Signature,
Deprecated, SourceFile, SourceDir, LineNumberTable,
LocalVariableTable, LocalVariableTypeTable, Synthetic,
EnclosingMethod, RuntimeVisibleAnnotations,
RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations,
RuntimeInvisibleParameterAnnotations, and AnnotationDefault. The
InnerClasses attribute name can be specified as well, referring to the
source name part of this attribute. For example, you should at least
keep the Exceptions, InnerClasses, and Signature attributes when
processing a library. You should also keep the SourceFile and
LineNumberTable attributes for producing useful obfuscated stack
traces. Finally, you may want to keep annotations if your code depends
on them. Only applicable when obfuscating.

Add This Line in proguard-rules.pro File

-keepattributes InnerClasses

More Details Found From https://stuff.mit.edu/afs/sipb/project/android/sdk/android-sdk-linux/tools/proguard/docs/index.html#manual/usage.html