Using Proguard to Obfuscate Android App with Libraries

Question:

 
I've just finished creating an Android app that requires the Dropbox.com API libraries. I'm now trying to build the application in 'Release' mode and would like to run proguard on the code in order to obfuscate it. However, whenever I attempt to run Proguard, I get the following error:
Proguard returned with error code 1. See console
Warning: com.dropbox.client2.DropboxAPI: can't find referenced class org.json.simple.JSONArray
Warning: com.dropbox.client2.DropboxAPI: can't find referenced class org.json.simple.JSONArray
Warning: com.dropbox.client2.DropboxAPI$Entry: can't find referenced class org.json.simple.JSONArray
Warning: com.dropbox.client2.DropboxAPI$Entry: can't find referenced class org.json.simple.JSONArray
Warning: com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.JSONParser
Warning: com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.JSONParser
Warning: com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.JSONParser
Warning: com.dropbox.client2.RESTUtility: can't find referenced class org.json.simple.parser.ParseException
Warning: there were 8 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars'),
         or perhaps the '-dontskipnonpubliclibraryclasses' option.
         java.io.IOException: Please correct the above warnings first.
         at proguard.Initializer.execute(Initializer.java:308)
         at proguard.ProGuard.initialize(ProGuard.java:210)
         at proguard.ProGuard.execute(ProGuard.java:85)
         at proguard.ProGuard.main(ProGuard.java:499)
I'm already including the '-dontskipnonpubliclibraryclasses' option and that's not helping me at all. I tried including the '-libraryjars' option, though, I may have been using it incorrectly as I'm not really sure how I'm intended to use that flag.
Does anyone have any ideas how I can correct this error? Right now, I'm unable to build my application while running it through Proguard. Any help is appreciated! Thanks!

 Answer 1:


Cfr. ProGuard manual > Troubleshooting > Warning: can't find referenced class
com.dropbox seems to depend on org.json. In theory, you should therefore add the org.json jar to your libs directory, so it can be processed and included in your application. In practice, your application works fine without it, so you can let ProGuard ignore the missing dependency:
-dontwarn org.json.**
or
-dontwarn com.dropbox.**
You shouldn't add -libraryjars, because any jars that you specify won't be present on Android devices unless you'd somehow manage to install them.
 
 

Answer2:

 
Well, through trial-and-error basically, I at least got a workaround going. I wouldn't consider this an actual 'answer' per se, however, my problem was solved by adding the following lines to my proguard.cfg file.
-libraryjars /lib/dropbox-android-sdk-1.2.1.jar
-libraryjars /lib/httpmime-4.0.3.jar
-libraryjars /lib/json_simple-1.1.jar

-dontwarn com.dropbox.client2.DropboxAPI
-dontwarn com.dropbox.client2.DropboxAPI$Entry
-dontwarn com.dropbox.client2.RESTUtility
Hopefully that'll help someone who finds themselves stuck with this or a very similar problem in the future.
 



Comments

Popular posts from this blog

How to draw an overlay on a SurfaceView used by Camera on Android?

Create EditText with dropdown in android

Android TCP Connection Chat application