使用 AndroidX 时,proguard-android-optimize.txt 中的“@Keep 支持注释”规则是否仍然适用?

Che*_*eng 5 android proguard android-r8 androidx

通常proguard-android-optimize.txt作为 proguard 文件来应用。

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
Run Code Online (Sandbox Code Playgroud)

然而,当我浏览完内容后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>(...);
}
Run Code Online (Sandbox Code Playgroud)

我想知道,如果我们使用 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>(...);
}
Run Code Online (Sandbox Code Playgroud)

Krz*_*tal 4

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