【问题标题】:How to make Proguard ignore external libraries?如何让 Proguard 忽略外部库?
【发布时间】:2011-12-05 00:05:33
【问题描述】:

我想使用 Proguard 主要是出于混淆的原因。

我的问题是我有三个库,Twitter4J 和两个路标库。当我尝试创建签名的 APK 时,这些库会导致错误。为了克服这个问题,我将以下内容放在proguard.config 文件中...

-dontwarn org.apache.commons.codec.binary.** 
-dontwarn org.slf4j.** 
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*   

虽然这消除了控制台中的错误,但当我将签名的 APK 加载到手机上时,它立即崩溃了。 DDMS 说这是由于 Twitter4J 中没有的类。

摆脱上面的"dontwarns" 并没有帮助。也没有添加dontshrink dontoptimise

我希望 Proguard 完全忽略这些库(因为它们无论如何都是开源的)。这可能吗?

【问题讨论】:

    标签: android proguard android-library


    【解决方案1】:

    试试这个:

    -keep class javax.** { *; }
    -keep class org.** { *; }
    -keep class twitter4j.** { *; }
    

    来自@CaspNZ 的帖子: Android Proguard with external jar

    【讨论】:

    • 非常感谢!我首先忽略了这篇文章,因为我认为我的错误不会由此解决,但不知何故它确实解决了。我只是不知道proguard的魔力……
    • @Boy 请在 android studio 中回复添加这些行的位置,在“proguard-project.txt”或“proguard-rules.pro”中
    • @ShirishHerwade 刚刚检查过,我已将其放入 proguard-rules.txt。检查你的 build.gradle 文件是否正确
    • 两个星号不再编译。还有其他解决方案吗?
    【解决方案2】:

    您应该能够在 proguard.cfg 中添加以下行以排除包(和子包)中的所有类

    -keep class org.apache.commons.codec.binary.**
    -keep interface org.apache.commons.codec.binary.**
    -keep enum org.apache.commons.codec.binary.**
    -keep class org.slf4j.**
    -keep interface org.slf4j.**
    -keep enum org.slf4j.**
    -keep class com.sun.syndication.io.**
    -keep interface com.sun.syndication.io.**
    -keep enum com.sun.syndication.io.**
    -keep class com.sun.syndication.feed.synd.**
    -keep interface com.sun.syndication.feed.synd.**
    -keep enum com.sun.syndication.feed.synd.**
    

    【讨论】:

    • 嗨@Nic Strong,感谢您的回复。我添加了代码,但是当我尝试导出签名的 APK 时出现很多错误,通常像“[2011-10-11 15:11:00 - canonV0003PRO] 警告:oauth.signpost.signature.OAuthMessageSigner:找不到引用的类org.apache.commons.codec.binary.Base64”。任何其他建议都非常感谢。梅尔
    • 您是否也将 oauth.signpost.** 添加到要保留的包列表中?
    • @NicStrong 请在 android studio 中回复在“proguard-project.txt”或“proguard-rules.pro”中添加这些行的位置
    • 两个星号不再编译。还有其他解决方案吗?
    【解决方案3】:

    我想补充一点,您应该在添加 proguard 规则后将您的项目与 Gradle 文件同步,否则它们可能无法正常工作。

    【讨论】:

      猜你喜欢
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 2015-01-14
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多