1

如果我通过在 project.properties 中注释掉“proguard.config=${sdk.dir}/tools/proguard...”禁用了 proguard,我的应用程序在调试以及导出到已签名的 apk 时也可以正常工作。

但是,如果我取消注释该行,我会收到一堆警告,并且 proguard 不会创建 apk。我可以通过将以下行添加到 proguard-project.txt 来抑制警告

-dontwarn com.sun.mail.imap.protocol.**
-dontwarn org.apache.harmony.awt.**
-dontwarn javax.activation.**

apk 将被创建,但不会在手机中执行。有趣的是,如果我删除这些行并使用“-dontshrink”,我会继续收到这些错误。我原以为这会解决这个问题。

我在http://developer.android.com/tools/help/proguard.html中发现我可能在我的配置中遗漏了一些 -keep 行,但这些行是什么并不明显。谁能提供线索?

默认的 proguard.cfg 文件试图涵盖一般情况,但您可能会遇到异常,例如 ClassNotFoundException,当 ProGuard 剥离应用程序调用的整个类时会发生这种情况。

当 ProGuard 剥离代码时,您可以通过在 proguard.cfg 文件中添加 -keep 行来修复错误。例如:

-保持公开课

    [2013-06-19 14:19:30 - Flashum2] Proguard returned with error code 1. See console
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslException
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.auth.callback.NameCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-06-19 14:19:30 - Flashum2] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-06-19 14:19:30 - Flashum2] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.DTK: can't 
.
.
.
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-06-19 14:19:30 - Flashum2] Warning: org.apache.harmony.awt.datatransfer.TextFlavor: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-06-19 14:19:30 - Flashum2]       You should check if you need to specify additional program jars.
    [2013-06-19 14:19:30 - Flashum2] Warning: there were 247 unresolved references to classes or interfaces.
    [2013-06-19 14:19:30 - Flashum2]          You may need to specify additional library jars (using '-libraryjars').
    [2013-06-19 14:19:30 - Flashum2] java.io.IOException: Please correct the above warnings first.
    [2013-06-19 14:19:30 - Flashum2]    at proguard.Initializer.execute(Initializer.java:321)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.initialize(ProGuard.java:211)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.execute(ProGuard.java:86)
    [2013-06-19 14:19:30 - Flashum2]    at proguard.ProGuard.main(ProGuard.java:492)

如果有帮助,这是我的 libs 文件夹中的 jar 列表:

05/31/2013  10:47 AM    <DIR>          .
05/31/2013  10:47 AM    <DIR>          ..
05/15/2012  09:22 AM            34,093 acra-3.1.2.jar
01/14/2013  09:07 AM            51,643 activation.jar
01/14/2013  09:06 AM            46,184 additionnal.jar
05/25/2013  04:14 PM           501,154 android-support-v13.jar
05/15/2012  09:22 AM           312,866 commons-lang3-3.0.1.jar
05/15/2012  09:22 AM           269,014 commons-net-3.0.1.jar
05/31/2013  10:47 AM           170,927 google-api-client-1.14.1-beta.jar
05/31/2013  10:47 AM             9,068 google-api-client-android-1.14.1-beta.jar
05/31/2013  10:47 AM           137,977 google-api-services-drive-v2-rev76-1.14.2-beta.jar
05/31/2013  10:47 AM           268,450 google-http-client-1.14.1-beta.jar
05/31/2013  10:47 AM            10,072 google-http-client-android-1.14.1-beta.jar
05/31/2013  10:47 AM             7,828 google-http-client-gson-1.14.1-beta.jar
05/31/2013  10:47 AM             6,038 google-http-client-jackson-1.14.1-beta.jar
05/31/2013  10:47 AM             6,076 google-http-client-jackson2-1.14.1-beta.jar
05/31/2013  10:47 AM            64,952 google-oauth-client-1.14.1-beta.jar
05/31/2013  10:47 AM           180,110 gson-2.1.jar
05/31/2013  10:47 AM           206,797 jackson-core-2.1.3.jar
05/31/2013  10:47 AM           232,131 jackson-core-asl-1.9.11.jar
05/31/2013  10:47 AM            33,015 jsr305-1.3.9.jar
01/14/2013  09:06 AM           440,508 mail.jar
05/15/2012  09:22 AM           134,421 zip4j_1.2.5.jar
4

1 回答 1

0

Maybe a bit late, but searching for a solution to a similar problem, I learned that you have to tell proguard to keep some classes in your libs jars. Refer to the log where it says Warning: ... and can't find referenced class ....

So in your case should be:

-keep class javax.security.** { *; }
-keep class java.beans.** { *; }
-keep class java.awt.** { *; }

and

-libraryjars libs/XYZ.jar

for every jar into /libs containing those classes.

于 2014-02-11T14:05:09.173 回答