【问题标题】:Getting "unresolved references" and "can't find superclass" warnings from Proguard从 Proguard 获取“未解决的引用”和“找不到超类”警告
【发布时间】:2016-08-05 10:15:51
【问题描述】:

我已将一些第三方源代码集成到我的 android 项目中,但在启用 proguard 的情况下构建它时遇到了麻烦。构建失败:

Warning: there were 123 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 201 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.

:app:transformClassesAndResourcesWithProguardForRelease FAILED

FAILURE: Build failed with an exception.

有许多注释和警告需要整理,我无法判断它的正面或反面。我已经尝试为似乎引起警告的所有内容添加--keep class example.package.** { *; },但它仍然失败。任何人都可以提出处理此类问题的策略吗?例如,如果我看到这个:

Warning: info.guardianproject.netcipher.client.MyDefaultClientConnectionOperator: can't find superclass or interface ch.boye.httpclientandroidlib.impl.conn.DefaultClientConnectionOperator

我该怎么办?

【问题讨论】:

标签: android build proguard minify android-proguard


【解决方案1】:

将以下内容添加到您的 proguard 文件中将解决编译问题:

-dontwarn info.guardianproject.netcipher.**

也就是说,您应该阅读随之而来的任何后果。 Proguard 通常发出警告是有充分理由的。

【讨论】:

  • 那你的答案为什么会是相关的?
【解决方案2】:

您收到这些警告的原因是 Guardianproject 搞砸了依赖项。如您所见,here NetCipher 没有任何依赖关系。而httpclientandroidlib 显然是一个外部项目。在Netcipher 内部,他们构建了.jar library,并没有将其打包到他们的库中。不幸的是,httpclientandroidlib 不能通过 jcenter 依赖获得。

有两种解决方案:

  1. @Tommie提议:添加

    -dontwarn info.guardianproject.netcipher.**
    

    给你proguard-rules.pro 文件,如果这些依赖不是必需的。你只是摆脱警告,有时这是一个好方法。但通常不起作用。然后进行第二步

  2. 您需要手动将httpclientandroidlib 添加到您的项目中。

    1. github 下载项目为.zip

    2. Add new module 到您的项目,将其命名为 httpclientandroidlib(名称是任意的。我这样命名仅供参考)

    3. 将文件夹结构ch.boye.httpclientandroidlib复制到新模块的src文件夹

    4. 将模块的AndroidManifest 替换为httpclientandroidlib 库中的那个。

    5. 将依赖添加到您的主要 aa 模块:

      compile project(':httpclientandroidlib')
      

然后您就可以开始使用该项目了。

【讨论】:

  • 谢谢。将compile 'com.madgag.spongycastle:prov:1.54.0.0' 添加到我的应用程序的 build.gradle 文件后,我遇到了同样的问题。根据 methodscount.com/?lib=com.madgag.spongycastle%3Aprov%3A1.54.0.0 ,它有 1 个依赖项,所以你知道我怎样才能找出那个依赖项是什么吗?
  • this solution 不适合你吗?
  • 它有效,谢谢,因此奖励给了你。在我的评论中,我问了一个不同的问题 - 关于 methodscount.com。
  • 哦..有“依赖列表”按钮。但仅显示依赖关系,它们由 build.gradle 文件中的 depencendies.compile 语句定义。
  • 抱歉,我没有看到您上一条消息中的链接。是的,其他解决方案已经解决了我所有的问题 - 似乎是因为我是“手动”包括我的 libs 文件夹中的 jar 和/或(更有可能)因为我缺少 pg 依赖项。现在一切正常! :-) 而且,如果它对其他人有帮助,我的 proguard-rules.pro 内容是 -keep class org.spongycastle.** { *; } -dontwarn org.spongycastle.** -keepattributes Exceptions,Deprecated,EnclosingMethod -keep public class * {public protected *;}
猜你喜欢
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
  • 2016-09-22
相关资源
最近更新 更多