通常将 proguard-android-optimize.txt
用作混淆文件。
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
但是,当我浏览 proguard-android-optimize.txt
...
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
我想知道,如果我们使用 AndroidX 而不是支持库,这样的规则是否仍然适用?我们是否应该在项目 proguard-project.txt
中明确添加以下规则?
# Understand the @Keep support annotation.
-keep class androidx.annotation.Keep
-keep @androidx.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <init>(...);
}
最佳答案
我刚刚检查了它并使用 androidx.annotation.Keep
注释类保留了它们。无需额外配置。
关于android - proguard-android-optimize.txt 中的 "@Keep support annotation"规则在使用 AndroidX 时是否仍然适用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58704385/