我的应用程序在调试中工作正常,当我导出到已签名的apk时,如果我通过在project.properties中注释掉“proguard.config = $ {sdk.dir} / tools / proguard ...”来禁用proguard。
但是,如果我取消注释该行,我会得到一堆警告,而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中发现我可能在配置中遗漏了一些保养线,但这些线路并不明显。任何人都可以提供线索吗?
默认的proguard.cfg文件试图涵盖一般情况,但是你 可能会遇到类似ClassNotFoundException的异常 当ProGuard剥离你的整个班级时,就会发生这种情况 应用程序调用。
当ProGuard通过添加a删除代码时,您可以修复错误 - 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
答案 0 :(得分:0)
也许有点晚了,但是在寻找类似问题的解决方案时,我了解到你必须告诉 proguard 在你的libs jar中保留一些类。请参阅日志Warning: ...
和can't find referenced class ...
。
所以在你的情况下应该是:
-keep class javax.security.** { *; }
-keep class java.beans.** { *; }
-keep class java.awt.** { *; }
和
-libraryjars libs/XYZ.jar
将每个jar放入包含这些类的/libs
。