Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android proguard, keep inner class

My android program has a class A, which has two static inner class. They are found to be stripped from .dex after applying proguard.

public class A{    ...   static class B{     ...   }    static class C{     ...   } } 

I have put the following lines in proguard.flags, but seem no luck.

-keep class com.xxx.A -keep class com.xxx.A$* 

Any hint?

like image 674
David Guan Avatar asked Dec 27 '12 19:12

David Guan


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.

Does ProGuard remove unused classes?

ProGuard Facts:Helps to remove unused classes, members & fields. It removes unused codes from your libraries as well. (Which means, any method or field that is not referenced anywhere will be removed by ProGuard Shrinker). Helps to reduce the build size by obfuscating the classes, methods, & fields with short names.

What is Dontwarn in ProGuard?

If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. ( http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass) Warning: there were 2 unresolved references to program class members. Your input classes appear to be inconsistent.

Where is ProGuard Android optimize txt?

The getDefaultProguardFile() refers default file “proguard-android. txt” which gets from the Android SDK tools/proguard/ folder. You can also use “proguard-android-optimize. txt” file for more code shrinking located on the same folder.


2 Answers

Try adding InnerClasses to the keep attributes. e.g:

-keepattributes Exceptions, InnerClasses, ... 

Also, try adding a body to the "keep" call with an asterisk, like so:

-keep class com.xxx.A$* {     *; } 
like image 178
Alexander Lucas Avatar answered Sep 19 '22 14:09

Alexander Lucas


This is what I had to do for my config

-keep class com.xxx.A { *; } -keep class com.xxx.A$B { *; } -keep class com.xxx.A$C { *; } 
like image 27
ajma Avatar answered Sep 17 '22 14:09

ajma