Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude external .jar from obfuscation by Proguard (Android project)?

When I export android project with proguard.cfg, all referenced .jar files are obfuscated as well. How can I exclude some of that .jars from obfuscation?

like image 500
alex2k8 Avatar asked Dec 17 '10 21: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.


3 Answers

If you don't want to edit the Ant script, you can add -keep options to proguard.cfg for the classes in those external jars. For instance:

-keep class othercode.** { *; }

Or with a regular expression containing a negator:

-keep class !mycode.** { *; }

The standard Ant script will still merge all referenced jars in the single output jar though.

like image 93
Eric Lafortune Avatar answered Oct 18 '22 02:10

Eric Lafortune


In your config file, set up your jars as library jars instead of input jars. This leaves them untouched.

-libjars <path/to/jars>
like image 25
danh32 Avatar answered Oct 18 '22 04:10

danh32


Using proguard maven plugin I do it like that

<inclusion>
   <groupId>foo.bar</groupId>
   <artifactId>foo-bar</artifactId>
   <library>true</library>
   <filter>!META-INF/**</filter>
</inclusion>

The

<library>true</library> 

lead to the external jar merged into the final jar after the obfuscation. But this might lead to the Manifest being overwritten. I haven't figured out yet how to avoid that the best way.

like image 1
haferblues Avatar answered Oct 18 '22 02:10

haferblues