最近在编译Android项目的时候,报告如下错误:
1 |
Error: Attribute Signature requires InnerClasses attribute. Check -keepattributes directive |
网上查找了很久,才了解到问题出在混淆配置上,具体原因为当混淆配置项中存在
1 |
-keepattributes Signature |
的时候,需要同步增加
1 |
-keepattributes InnerClasses |
更详细的解释参考如下:
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:
1 |
-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.