【问题标题】:Using ProGuard with Android在 Android 中使用 ProGuard
【发布时间】:2012-06-30 02:28:22
【问题描述】:

我在处理 ProGuard 和 Android 时遇到问题。

我在网上搜索了几个小时,发现了多种混淆 Android 应用程序的方法。现在我正在尝试一种看起来最简单的方法,所以:

  • 我在项目根目录下创建了config.cfg文件
  • 我在我的project.properties 中添加了proguard.config=config.cfg
  • 我使用 Eclipse 导出向导导出并签署 .apk 文件

我收到一条消息说 Proguard returned with error code 1. See console 并在控制台中:

Proguard returned with error code 1. See console
Note: there were 3847 duplicate class definitions.
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
      You should check if you need to specify additional program jars.
Warning: there were 4 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars').
Error: Please correct the above warnings first.

即使我使用 Proguard 官方网站提供的配置或默认配置,我也会有错误。
这是我的自定义配置(myProject/config.cfg):

-injars      bin/classes
-injars      libs
-libraryjars "C:\Program Files\Android\android-sdk\platforms\android-13\android.jar"

-dontskipnonpubliclibraryclasses
-optimizationpasses 5
-printmapping map.txt
-flattenpackagehierarchy
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Application
-keep public class * extends android.app.Activity
-keep public class * extends android.app.PreferenceActivity
-keep public class * extends android.view.View
-keep public class * extends android.widget.BaseAdapter
-keep public class * implements android.view.View.OnTouchListener

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

我无法让它工作...任何想法将不胜感激!

注意:我使用存储在 libs 中的 Jackson JSON 库我的项目文件夹

【问题讨论】:

    标签: java android eclipse obfuscation proguard


    【解决方案1】:

    1) ProGuard manual > Troubleshooting > Note: duplicate definition of program/library class

    Android Ant/Eclipse 版本已经为您指定了 -injars/-libraryjars。如果您在配置中再次指定它们,ProGuard 会指出它们是重复的。所以不要指定 -injars/-libraryjars。

    2) ProGuard manual > Troubleshooting > Warning: can't find referenced class

    org.w3c.dom.bootstrap.DOMImplementationRegistry 不存在于输入代码中,但 com.fasterxml.jackson.databind.ext.DOMSerializer 正在使用它。如果您的应用程序仍然有效,您可以让 ProGuard 接受它:

    -dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry
    

    【讨论】:

    • 感谢您的帮助。编译/混淆可以正常工作,但是当我单击将我重定向到具有使用 JSON 库的对象的 Activity 的按钮时,应用程序崩溃...
    • 对我来说也是...它没有抛出错误,但我的 flexJson 已停止工作
    • @miNde 你找到这个问题的答案了吗?谢谢!
    • @eyyo 没有看到你的评论。我不太记得了,但我可能忽略了警告,或者只是禁用了优化,这可能不是最好的主意。但我需要一个快速的解决方案来为某人发布应用程序。
    【解决方案2】:

    此处提供的 ProGuard 配置文件:

    https://groups.google.com/forum/#!msg/robospice/xGLRbGkLwQU/cAkaUQF34RsJ

    解决我的问题!

    【讨论】:

    • 那个配置文件没有指定 injarsoutjars
    【解决方案3】:

    我刚遇到同样的问题,我通过引用 JRE rt.jar 文件解决了它:

    -libraryjars /lib/rt.jar

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 2014-09-28
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      相关资源
      最近更新 更多