【问题标题】:How to keep field's annotation with proguard at runtime如何在运行时使用 proguard 保留字段的注释
【发布时间】:2019-05-14 16:19:01
【问题描述】:

我正在开发一个 Android 应用程序。在我尝试使用 Proguard 混淆代码之前,该应用程序就像一个魅力一样工作。

import com.mobsandgeeks.saripaar.annotation.NotEmpty;

public class TaccuinoFragment extends Fragment {

    private TaccuinoViewModel mViewModel;

    @NotEmpty(messageResId = R.string.error_campo_obbligatorio)
    TextInputLayout titoloLayout;

}

gradle 配置:

release {
  signingConfig signingConfigs.config
  zipAlignEnabled true
  minifyEnabled true
  proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), System.getenv("GRADLE_PROGUARD_CONFIG_FILE"), 'proguard-rules.pro'
}

我尝试了以下Proguard的配置:

-keepclasseswithmembernames class * {  @com.mobsandgeeks.saripaar.annotation.** <fields>;}

如何在运行时保留NotEmpty 注释?提前谢谢你。

【问题讨论】:

    标签: java android proguard android-proguard


    【解决方案1】:

    使用:

    -keepattributes *Annotation*

    【讨论】:

    • 喜欢这个-keepattributes @com.mobsandgeeks.saripaar.annotation.**?
    • 不,只是*Annotation*,但是如果你使用gradle,你可能需要在注解'*Annotation*'周围加上单引号
    猜你喜欢
    • 2018-05-10
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多