Using Proguard to Obfuscate Android App with Dropbox.com Libraries

烂漫一生 提交于 2020-01-01 02:40:17

问题


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!


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/8030532/using-proguard-to-obfuscate-android-app-with-dropbox-com-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!