58

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?

hardillb
  • 54,545
  • 11
  • 67
  • 105
Mel
  • 6,214
  • 10
  • 54
  • 71

3 Answers3

73

Try this:

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

Cf post from @CaspNZ: Android Proguard with external jar

Community
  • 1
  • 1
Murphy
  • 4,858
  • 2
  • 24
  • 31
  • Thanks a lot! I first ignored this post as I thought my errors would not be solved by this, but somehow it did. I just don't know the magic of proguard... – Boy Jul 01 '14 at 13:50
  • @Boy plz reply in android studio where to add these lines, either in 'proguard-project.txt' or 'proguard-rules.pro' – Shirish Herwade Apr 04 '16 at 16:04
  • 1
    @ShirishHerwade just checked and I've put it in the proguard-rules.txt. Check your build.gradle for the correct file – Boy Apr 04 '16 at 19:38
  • 1
    Two asterisks don't compile anymore. Any other solutions? – Daniel Jul 16 '20 at 10:14
17

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.**
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Nic Strong
  • 6,532
  • 4
  • 35
  • 50
  • Hi @Nic Strong, hanks for the reply. I added the code but when I tried to export the signed APK a lot of errors typically like "[2011-10-11 15:11:00 - canonV0003PRO] Warning: oauth.signpost.signature.OAuthMessageSigner: can't find referenced class org.apache.commons.codec.binary.Base64". Any other suggestions greatly appreciated. Mel – Mel Oct 11 '11 at 13:51
  • Did you also add oauth.signpost.** to the list of packages to keep? – Nic Strong Oct 11 '11 at 21:57
  • @NicStrong plz reply in android studio where to add these lines, either in 'proguard-project.txt' or 'proguard-rules.pro' – Shirish Herwade Apr 04 '16 at 16:07
  • Two asterisks don't compile anymore. Any other solutions? – Daniel Jul 16 '20 at 10:15
0

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

urgentx
  • 3,832
  • 2
  • 19
  • 30