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

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

我在尝试以发布模式构建应用程序时遇到此错误。

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

我的 proguard-rules.pro 行如下所示:

-keepattributes Signature

编译器指的是什么内部类?我遗漏了什么?

Signature(Java 8 或更高版本)仅适用于 Java 8 或更高版本和 InnerClasses(Java 5 或更高版本),因此请检查您的 Android Studio 是否正在使用 Java SDK版本。 请使用以下设置更新您的 Proguard 配置

将此行添加到您的 proguard-rules.pro 文件中:

-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.

有关 -keepattributes 的更多详细信息以及您可以应用的更多设置,请参阅下文 link。

Proguard options

参考: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.

在 proguard-rules.pro 文件中添加这一行

-keepattributes InnerClasses

更多详细信息来自 https://stuff.mit.edu/afs/sipb/project/android/sdk/android-sdk-linux/tools/proguard/docs/index.html#manual/usage.html