Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper Proguard configuration to keep static inner class

I have the following:

public class A extends B {
    static class C {
        Object field1;
        int field2;
        boolean field3;
    }
}

I cannot get the C class via reflection!

I've tried the following:

-keep class com.path.to._class.A$** {*;}

-keep class com.path.to._class.A$* {*;}

-keep class com.path.to._class.A$C {*;}

-keep class com.path.to._class.A$C {
    <fields>;
}

-keep class com.path.to._class.A$C {
    Object field1;
    int field2;
    boolean field3;
}

None of the above worked. Am I doing something completely wrong here?

Perhaps its worth mentioning that B extends View...

like image 457
TacB0sS Avatar asked Oct 14 '13 19:10

TacB0sS


People also ask

How do you keep a class in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

Can inner classes be static?

Inner Classes As with instance methods and variables, an inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields. Also, because an inner class is associated with an instance, it cannot define any static members itself.

Which is true static inner class?

Which statement is true about a static nested class? You must have a reference to an instance of the enclosing class in order to instantiate it.


1 Answers

All of those should work (only Object -> java.lang.Object). You can check bin/proguard/seeds.txt to see if they are listed. Otherwise, you might be modifying the wrong configuration file, or there might be a typo in the names.

like image 180
Eric Lafortune Avatar answered Nov 15 '22 00:11

Eric Lafortune