使用Proguard通过Dropbox.com库混淆Android应用程序

时间:2011-11-06 21:29:43

标签: java android dropbox proguard dropbox-api

我刚刚创建了一个需要Dropbox.com API库的Android应用。我现在正试图在'Release'模式下构建应用程序,并希望在代码上运行proguard以便对其进行模糊处理。但是,每当我尝试运行Proguard时,都会收到以下错误:

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)

我已经加入了'-dontskipnonpubliclibraryclasses'选项,但这根本没有帮助我。我尝试使用'-libraryjars'选项,但我可能一直在使用它,因为我不确定我打算如何使用该标志。

有没有人有任何想法如何纠正此错误?现在,我无法在通过Proguard运行它时构建我的应用程序。任何帮助表示赞赏!谢谢!

2 个答案:

答案 0 :(得分:10)

(CFR)。 ProGuard manual > Troubleshooting > Warning: can't find referenced class

com.dropbox似乎依赖于org.json。理论上,您应该将org.json jar添加到libs目录中,以便可以处理它并将其包含在您的应用程序中。实际上,没有它你的应用程序工作正常,所以你可以让ProGuard忽略缺少的依赖:

-dontwarn org.json.**

-dontwarn com.dropbox.**

你不应该添加-libraryjars,因为你指定的任何jar都不会出现在Android设备上,除非你以某种方式设法安装它们。

答案 1 :(得分:2)

好吧,基本上通过反复试验,我至少得到了解决方法。我不认为这本身就是一个真正的“答案”,但是,通过在我的proguard.cfg文件中添加以下行来解决我的问题。

-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

希望这将有助于将来发现自己陷入此问题或非常类似问题的人。