My app is not obfuscated due to -dontoptimize and -dontobfuscate rules in progaurd-rules.pro

Using the following configuration

-dontoptimize 
-dontobfuscate 
-keepattributes SourceFile,LineNumberTable -keep class org.whispersystems.** { *; } 
-keep class org.thoughtcrime.securesms.** { *; } 
-keepclassmembers class ** { public void onEvent*(**); }

after adding the above lines of code, my whole app code is not getting obfuscated now because of just these two lines

-dontoptimize 
-dontobfuscate.

If I remove these two configuration options my app crashes during serialization of signal protocol classes.

my configuration in build.gradle file

release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile( proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard.cfg' useProguard true debuggable false } debug { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile( 'proguard-android-optimize.txt'), 'proguard-rules.pro', 'proguard.cfg' useProguard true debuggable false }

I tried adding rules for signal in separate file proguard.cfg , as you can see above. but no luck :frowning:
kindly let me know how to obfuscate my app.

1 Like

Hi Naveedcs,

ProGuard’s name obfuscation can make your application crash where it relies on reflection, therefore you will need to create -keep options to preserve those parts of code. In serialized classes you will need to preserve the names of the fields, that will make sure the keys in the serialized data will not contain obfuscated names. You can preserve the field names with a -keep rule as follows;

-keepclassmembers class com.example.MyData {
    <fields>;
}

We documented the frequently occurring exceptions caused by ProGuard together with some information on how to tackle these in our troubleshooting guide, here: https://www.guardsquare.com/en/products/proguard/manual/troubleshooting

Best regards,

Jonas

1 Like