代码之家  ›  专栏  ›  技术社区  ›  Cheok Yan Cheng

是“@Keep support annotation”规则在proguard android中吗-优化.txt在使用AndroidX时仍然适用?

  •  0
  • Cheok Yan Cheng  · 技术社区  · 5 年前

    proguard-android-optimize.txt 作为proguard文件。

    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.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>(...);
    }
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Krzysztof Misztal    5 年前

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

        2
  •  0
  •   Jaimil Patel    4 年前

    如果你不使用proguard android-优化.txt或者是前守卫-安卓.txt,您应该添加

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

    或者,你的 @Keep 会变成@a

    如果你使用proguard android-优化.txt或者是前守卫-安卓.txt,它仍然有效。

    希望对你有用。

    推荐文章