使用 Proguard 处理 Jackson 库后混淆时出错

发布于 2024-12-19 23:48:58 字数 1316 浏览 0 评论 0原文

在使用 Proguard 搜索了与混淆问题相关的各种查询后,我觉得我可能是唯一一个遇到这个特定问题的人。因此,该帖子。

我有一个相当标准的 Android 应用程序,它使用基于 JSON 的 REST 调用来交换数据。我使用 Jackson 库来解析 JSON 数据。一切都运行得非常完美,直到我们决定使用 Proguard 对我们的发布版本进行混淆。在解决了一系列与回调相关的问题之后,我终于遇到了与 Jackson 库相关的问题。

基本上,ObjectMapper om = new ObjectMapper() 行 - 只是不起作用!我在该行不断收到以下错误:

Caused by: java.lang.ExceptionInInitializerError
    at org.codehaus.jackson.map.ObjectMapper.<clinit>(Unknown Source)
    ... 8 more
Caused by: java.lang.NullPointerException
    at org.codehaus.jackson.map.introspect.VisibilityChecker$Std.<init>(Unknown Source)
    at org.codehaus.jackson.map.introspect.VisibilityChecker$Std.<clinit>(Unknown Source)
    ... 9 more

在阅读了许多与包含外部库、使 proguard 忽略 Jackson 库类、打开和关闭优化以及缩小标志相关的其他帖子后,我现在一无所知。

为了杰克逊的缘故,我在 proguard.cfg 文件中包含了各种内容 -

-dontskipnonpubliclibraryclassmembers
-dontoptimize
-dontshrink
-libraryjars xtraLibs/joda-time-1.6.2.jar;xtraLibs/xml-apis.jar;xtraLibs/jsr311-api-0.8.jar;xtraLibs/stax2-api-3.0.0.jar;xtraLibs/httpmime-4.0.1.jar

其中,我切换了 dontoptimizedontshrink 标志。然而,结果始终是一样的。

在我尝试解决这个问题的所有时间中,我对 Proguard 库所付出的努力感到惊讶和敬畏。只是当事情不起作用时,它们会有点混乱

Proguard 版本 - 4.6

after scouring through all sorts of queries related to issues w/ obfuscation using Proguard, I've come to the point where I feel I might be the only one having this particular issue. Hence, the post.

I have a fairly standard android app which makes use of JSON-based REST calls to exchange data. I make use of the Jackson library to parse the JSON data. Everything had been working flawlessly, until we decided to incorporate obfuscation for our release builds using Proguard. After sorting out a world of callback related problems, I'm finally stuck with a problem related to the Jackson library.

basically, the line ObjectMapper om = new ObjectMapper() - just doesn't work! I keep getting the following error at that line:

Caused by: java.lang.ExceptionInInitializerError
    at org.codehaus.jackson.map.ObjectMapper.<clinit>(Unknown Source)
    ... 8 more
Caused by: java.lang.NullPointerException
    at org.codehaus.jackson.map.introspect.VisibilityChecker$Std.<init>(Unknown Source)
    at org.codehaus.jackson.map.introspect.VisibilityChecker$Std.<clinit>(Unknown Source)
    ... 9 more

After reading a host of other posts related to including external libraries, making proguard ignore the Jackson library classes, turning on and off optimization and shrinking flags, I'm just clueless right now.

The various things I've included in my proguard.cfg file for Jackson's sake -

-dontskipnonpubliclibraryclassmembers
-dontoptimize
-dontshrink
-libraryjars xtraLibs/joda-time-1.6.2.jar;xtraLibs/xml-apis.jar;xtraLibs/jsr311-api-0.8.jar;xtraLibs/stax2-api-3.0.0.jar;xtraLibs/httpmime-4.0.1.jar

amongst these, I've toggled the dontoptimize and dontshrink flags. However, the result has always been the same.

In all the time I've spent in trying to solve this issue, I've come to be amazed and awed by the kind of effort gone into the Proguard library. It's just that when things don't work, they're a bit obfuscated.

Proguard version - 4.6

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

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

发布评论

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

评论(1

落叶缤纷 2024-12-26 23:48:58

从堆栈跟踪中并不明显,但 Jackson 需要一些注释,ProGuard 默认情况下会删除这些注释。比照。 ProGuard手册>示例> 处理注释

-keepattributes *Annotation*,EnclosingMethod

此外,正如不祥的包名称“org.codehaus.jackson.map.introspect”所暗示的那样,Jackson 对解析的类进行内省以查找 getter 和 setter。在不知情的情况下,ProGuard 可能会删除或重命名它们,因为您的代码可能不会显式使用它们。您可能必须明确保留它们,例如:

-keep public class mydatapackage.** {
  public void set*(***);
  public *** get*();
} 

It's not obvious from the stack trace, but Jackson needs some annotations, which ProGuard removes by default. Cfr. ProGuard manual > Examples > Processing annotations:

-keepattributes *Annotation*,EnclosingMethod

Furthermore, as the ominous package name 'org.codehaus.jackson.map.introspect' suggests, Jackson performs introspection on parsed classes to find getters and setters. Without knowing any better, ProGuard may be removing or renaming these, because your code might not use them explictly. You may have to keep them explicitly, e.g.:

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