Android proguard, keep inner class

微笑、不失礼 提交于 2019-11-27 13:24:54
Alexander Lucas

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$* {
    *;
}

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 { *; }
GameSalutes

This did the trick for me

-keepattributes InnerClasses
 -keep class com.yourpackage.YourClass**
 -keepclassmembers class com.yourpackage.YourClass** {
    *;
 }

It may be a bit overkill with the wildcards but I wanted to make sure I didn't miss anything. The main thing is you need the InnerClasses attributes the keep on the class and the keepclassmembers on the class.

if you don't want all inner class and members in some package to be obfuscated you can add lines in proguard-rules.pro

    -keep class com.xxx.task.*$* {
        *;
    }

Your configuration looks correct. You should double-check that you haven't misspelled the class names. If the spelling in incorrect, ProGuard should print out a note about it. You can also specify -printseeds seeds.txt, and see if your classes are listed in the resulting file. If they are listed, the classes are also in the processed code.

As Alexander Lucas mentioned, you may also want to keep the fields and methods of these classes -- that depends on your requirements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!