How to keep field’s annotation with proguard at runtime Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to keep field’s annotation with proguard at runtime without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m working on an Android App. The application works like a charm until I tried to obfuscate the code with Proguard.

import com.mobsandgeeks.saripaar.annotation.NotEmpty;

public class TaccuinoFragment extends Fragment {

    private TaccuinoViewModel mViewModel;

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

}

The gradle configuration:

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

I tried the following Proguard’s configuration:

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

How can I keep the NotEmpty annotation at runtime? Thank you in advance.

Answer

use:

-keepattributes *Annotation*

We are here to answer your question about How to keep field’s annotation with proguard at runtime - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji