2

proguard-android-optimize.txt作为proguard文件申请是很常见的。

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>(...);
}
4

2 回答 2

1

我只是检查了它并用androidx.annotation.Keep它们注释类。无需额外配置。

于 2020-01-28T14:13:11.327 回答
1

如果你不使用 proguard-android-optimize.txt 或 proguard-android.txt,你应该添加

-keep class androidx.annotation.Keep {*;}

或者,您@Keep将转向@a

如果您使用 proguard-android-optimize.txt 或 proguard-android.txt,它仍然可以工作。

希望它对你有用。

于 2020-06-11T02:52:22.223 回答