简体   繁体   中英

ProGuard - How to keep methods and obfuscate them at the same time?

I am trying to manually obfuscate my Android application (yes, I know, it's a pain) and for that I need to keep all the methods I implement yet also obfuscate them with ProGuard at the same time.

I have tried changing the config like this:

-keep class com.project.x.* {

}

But it kept all the class names and method names and still removed my unused code.

What can I do to solve this issue?

Thanks in advance!

As CommonsWare explained, it seems unlikely that you want to keep unused methods and yet have their names obfuscated, but ProGuard supports it as follows:

-keepclassmembers,allowobfuscation class com.project.x.** {
    <methods>;
}

This forcibly keeps all methods (but not all classes) in the specified package (and its subpackages), but still allows their names to be obfuscated.

Use keep option modifiers - see here

I think you'd do something like this:

-keep,allowoptimization class com.project.x.* {

}

But to quote the documentation: "This modifier is only useful for achieving unusual requirements."

Have you tried to reverse enginner to see that this is something you need to do? My impression of keep is that it will preserve the class as an entry point to the app, but that it doesn't stop it optimising and obfuscating the methods of those classes internally.

Maybe all you want is -keepnames see that link above for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM