Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obfuscate only com.foo.* and com.bar.* (ProGuard)?

I want to obfuscate only some packages:

com.foo.* com.bar.* 

I have tried

-keepclasseswithmembers class **, !com.foo.**, !com.bar.** { *; } 

and

-keepclasseswithmembers class !com.foo.** { *; } -keepclasseswithmembers class !com.bar.** { *; } 

In both cases the classes from com.foo.* and com.bar.* was NOT obfuscated.

like image 944
alex2k8 Avatar asked Dec 27 '10 00:12

alex2k8


People also ask

What is ProGuard obfuscation?

ProGuard is a command-line tool that reduces app size by shrinking bytecode and obfuscates the names of classes, fields and methods. It's an ideal fit for developers working with Java or Kotlin who are primarily interested in an Android optimizer.

Does ProGuard obfuscate code?

You can obfuscate Android code to provide security against reverse engineering. You can use the Android ProGuard tool to obfuscate, shrink, and optimize your code.

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.


1 Answers

This should work

-keep class !com.foo.**,!com.bar.** { *; } 

You can find a summary of the various -keep options at https://www.guardsquare.com/manual/configuration/usage#keepoptions

You can find the explanation of ProGuard's regular expressions at https://www.guardsquare.com/manual/configuration/usage#filters

like image 81
Eric Lafortune Avatar answered Sep 29 '22 07:09

Eric Lafortune