Search code examples
androidproguard

How to prevent class member obfuscation when using multiple classes related classes?


I have the following location in my project:

package com.example.data

Where I have placed four classes, A, B, C and D that look like this:

public class A {
    public List<B> bList = new ArrayList<>();
}

public class B {
    public List<C> CList = new ArrayList<>();
}

public class C {
    public D d;
}

public class D {
    public String s;
}

Now, in my ProGuard I can add simething like this:

-keepclassmembers class com.example.data.data.A{*;}
-keepclassmembers class com.example.data.data.B{*;}
-keepclassmembers class com.example.data.data.C{*;}
-keepclassmembers class com.example.data.data.D{*;}

But is there a more simpler way I can avoid obfuscation in my classes configuration?


Solution

  • You can give a rule to the package level. So all classes under this package will not be obfuscated. In your proguard rules file, for example in proguard-common.pro file, add the below code.

    -keep class com.example.data.** { *; }