How to make Proguard ignore external libraries?

AndroidProguardAndroid Library

Android Problem Overview


I want to use Proguard mainly for obfuscation reasons.

My problem is that I have three libraries, Twitter4J and two signpost libraries. These libraries caused errors when I tried to create an signed APK. To get over this I put the following in the proguard.config file...

-dontwarn org.apache.commons.codec.binary.** 
-dontwarn org.slf4j.** 
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*   

While this got rid of the errors in the console, when i loaded my signed APK onto my mobile phone it instantly crashed. The DDMS said this was due to a class not found in Twitter4J.

Getting rid of the "dontwarns" above did not help. Neither did adding dontshrink dontoptimise.

I would like Proguard to completely ignore the libraries (as they are open source anyway). Is this possible?

Android Solutions


Solution 1 - Android

Try this:

-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }

Cf post from @CaspNZ: https://stackoverflow.com/questions/6870773/android-proguard-with-external-jar/6870844#6870844

Solution 2 - Android

You should be able to add to the proguard.cfg the following lines to exclude all classes within a package (and subpackages)

-keep class org.apache.commons.codec.binary.**
-keep interface org.apache.commons.codec.binary.**
-keep enum org.apache.commons.codec.binary.**
-keep class org.slf4j.**
-keep interface org.slf4j.**
-keep enum org.slf4j.**
-keep class com.sun.syndication.io.**
-keep interface com.sun.syndication.io.**
-keep enum com.sun.syndication.io.**
-keep class com.sun.syndication.feed.synd.**
-keep interface com.sun.syndication.feed.synd.**
-keep enum com.sun.syndication.feed.synd.**

Solution 3 - Android

I'd like to add that you should sync your project with Gradle files after adding proguard rules, otherwise they may not work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMelView Question on Stackoverflow
Solution 1 - AndroidMurphyView Answer on Stackoverflow
Solution 2 - AndroidNic StrongView Answer on Stackoverflow
Solution 3 - AndroidurgentxView Answer on Stackoverflow