使用Proguard混淆Android应用与Dropbox.com库



我刚刚创建了一个需要Dropbox.com API库的Android应用程序。我现在试图在"发布"模式下构建应用程序,并希望在代码上运行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运行它。任何帮助都是感激的!谢谢!

ProGuard手册>故障排除>警告:无法找到引用的类

com。Dropbox似乎依赖于org.json。因此,理论上,您应该添加组织。将Json jar放到libs目录中,这样就可以处理它并将其包含在应用程序中。实际上,你的应用程序没有它也能正常工作,所以你可以让ProGuard忽略缺失的依赖项:

-dontwarn org.json.**

-dontwarn com.dropbox.**

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

嗯,基本上通过试错,我至少找到了一个解决办法。我不认为这是一个真正的"答案"本身,然而,我的问题是通过在我的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

希望这能帮助那些发现自己在将来遇到这个问题或非常类似问题的人。

最新更新