Proguard 的 jar 文件出现问题,如何找到丢失的 jar?

发布于 2024-10-17 05:10:18 字数 2344 浏览 2 评论 0原文

当我尝试使用 Proguard 导出我的 apk 时,出现很多错误(超过 400 个),类似于:

Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper

并且

org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource

我正在使用 Jackson Json 库,错误似乎与此相关。

研究这个错误时,我从 Proguards FAQ 中发现了以下内容:

如果存在对类或接口的未解析引用,您很可能忘记指定一个重要的库。为了正确处理,必须指定代码引用的所有库,包括 Java 运行时库。要指定库,请使用 -libraryjars 选项。

在 SO 上搜索,我发现了很多与此相关的未解答的问题,但一般意义是我正在使用的 jar 文件(在本例中为 Jackon JSON)依赖于更多库,并且需要将它们添加到 Proguard 的配置文件中如何。

但是,我不知道如何确定需要哪些罐子以及它们在哪里。警告提到了许多不同的包,例如 javax.ws.rs.ext、org.joda.time、org.codehaus.stax2、javax.xml.stream 等。

  1. 如何确定哪些 jar 包含这些包?例如,javax.ws.rs.ext.** 类需要什么 jar?
  2. 我如何找出这些 jars 在哪里以及 Proguard 中的 -libraryjars 会使用什么路径?

非常感谢


编辑: 我还应该提到我正在使用 Android 库项目 设置。这些 jar 位于主 Library 项目中,实际工作项目有其构建路径,包括 Library 项目中的 jar。不知道这是否有什么不同,但我想我应该提一下。


更新 只是为了测试,我将 Jackson 从构建路径和代码中完全删除,现在 Proguard 已成功完成。问题仍然存在......处理这些错误的正确方法是什么?

Eclipse 中的 Android 导出向导是否会自动将 /lib/ jar 添加到 proguard,还是必须将它们全部手动添加到 proguard 配置文件中,如下所示:

-libraryjars C:/Project/lib/somjar.jar

我确实在 jackson 中尝试过这样做,但没有任何区别。这是否意味着我还必须找到警告中提到的类所需的所有 jar 并添加它们?它们会在 sdk 中还是在 java 安装中?

抱歉,如果这些是愚蠢的问题,但在过去的几个小时里我一直在试图解决这个问题,但不知道该怎么做。

再次感谢


再次更新

所以更多的搜索,结合Benjamin的建议,我发现一些缺失的类在rt.jar中,该jar位于jdk的lib文件夹中。所以我最终添加

-libraryjars  <java.home>/lib/rt.jar

到 proguard.cfg 文件中,并将警告从 485 减少到 204。嘿,我想这就是……剩下的警告描述了我根本找不到的类。该应用程序在不运行 proguard 的情况下运行得很好,所以这些类一定在某个地方,对吗?或者这些警告是我应该使用 -dontwarn 的吗?

其余的类位于这些包中:

org.joda.time.
org.codehaus.stax2.
javax.ws.rs.

所以现在我只需要一种方法来弄清楚:

  1. 哪些 jar 具有这些类
  2. 这些 jar 在哪里,以便我可以将它们包含在 proguard 配置文件中

When I try to export my apk with Proguard I get a lot of errors (over 400) similar to:

Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper

and

org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource

I am using the Jackson Json library, and the errors seem related to that.

Researching this error I found the following from Proguards FAQ:

If there are unresolved references to classes or interfaces, you most likely forgot to specify an essential library. For proper processing, all libraries that are referenced by your code must be specified, including the Java run-time library. For specifying libraries, use the -libraryjars option.

Searching around on SO I found a lot of unanswered questions related to this, but the general sense was that the jar file I am using (in this case Jackon JSON) is relying on more libraries and they need to be added to Proguard's config file some how.

However, I can't figure out how to determine what jars are needed and where they are. The warnings mention a lot of different packages such as javax.ws.rs.ext, org.joda.time, org.codehaus.stax2, javax.xml.stream, etc.

  1. How do I determine what jars contain those packages? For example, what jar is required for the javax.ws.rs.ext.** classes?
  2. How do I figure out where those jars are and what path would be used with -libraryjars in Proguard?

Thanks much


Edit: I should also mention that I am using an Android Library Project setup. The jars are in the main Library project, and the actual working project has their build paths including the jars in the Library project. Don't know if that makes a difference but thought I should mention it.


Update Just to test, I completely removed the jackson far from the build path and from my code and now Proguard completes successfully. The questions still remain... What is the correct approach for handling these errors?

Does the Android export wizard in Eclipse automatically add the /lib/ jars to proguard or do they all have to be added manually in the proguard config file like this:

-libraryjars C:/Project/lib/somjar.jar

I did try that for the jackson one but it didn't make any difference. Does this mean I also have to find all of the jars that are needed for the classes mentioned in the warnings and add those? Would they be in the sdk or in the java installation?

Sorry if these are stupid questions, but I have been trying to figure this out for the last couple hours and have no idea what to do.

Thanks again


Update Again

So more searching, combined with Benjamin's suggestion, I found some of the missing classes were in rt.jar, which is in the jdk's lib folder. So I ended up adding

-libraryjars  <java.home>/lib/rt.jar

To the proguard.cfg file and brought the warnings from 485 down to 204. Hey I guess that's something... The remaining warnings describe classes that I cannot find at all. The app works just fine without running proguard, so these classes must be somewhere right? Or are these warnings that I should use -dontwarn with?

The remaining classes are in these packages:

org.joda.time.
org.codehaus.stax2.
javax.ws.rs.

So now I just need a way to figure out:

  1. What jars have these classes
  2. Where are these jars so I can include them in the proguard config file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不寐倦长更 2024-10-24 05:10:18

我在使用 Proguard 时遇到了类似的问题,并且在使用 osmdroid.jar 时遇到了类似的错误,它构建得很好,没有混淆。这个 jar 一定有我的应用程序不需要的外部依赖项。幸运的是,作者列出了所需的 jar,一旦我下载了它们并通过 -libraryjars 选项告诉 Proguard,Proguard 构建就可以了。

关于您丢失的 jars(您可能并不真正需要,但 Proguard 认为您可能需要!),您应该在以下位置找到它们:

org.joda.time
(罐子位于压缩包内)

org.codehaus.stax2。

javax.ws。 rs.

I've had similar problems with Proguard and similar errors I was using an osmdroid.jar which built OK unobfuscated. This jar must have had external dependencies which my application didn't need. Fortunately the authors listed the jars needed and once I downloaded them and told Proguard via the -libraryjars option, the Proguard build was OK.

Re your missing jars (which you probably don't really need, but Proguard thinks you might!), you should find them at:

org.joda.time
(The jar's inside the zip)

org.codehaus.stax2.

javax.ws.rs.

棒棒糖 2024-10-24 05:10:18

我只能回答第一部分:
尝试

http://www.findjar.com

,您可能会找到所需 jar 文件的名称
像这样

I only can provide an answer for the first part:
Give

http://www.findjar.com

a try, there you might find the names of the needed jar files
like so

救星 2024-10-24 05:10:18

您不需要包含 Proguard 的库;您需要指示 Proguard 保留类名和其他一些内容。我自己尝试了一下,最终得到了类似于 的内容此讨论

-keepnames class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

如果您仍然遇到崩溃 - 我建议大力测试! - 您可能希望保持 Jackson 完好无损:(

-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

请注意,后者会生成更大的文件。)

You don't need to include the libraries for Proguard; you need to instead instruct Proguard to keep the class names and some other stuff. I toyed around with it a bit myself, and I ended up with something similar to this discussion:

-keepnames class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

If you're still experiencing crashes—and I would suggest testing vigorously!—you might want to keep Jackson completely intact with:

-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

(Note that the latter produces a larger file.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文