无法修复Android Proguard返回错误代码1错误

时间:2013-08-28 16:38:51

标签: android proguard

当我尝试在我的Android应用程序中使用proguard时只需添加

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt

到我的project.properties文件,APK导出失败并显示消息 Proguard Returned with error code 1

这是我的project.properties文件

target=android-18
android.library.reference.1=../LVL
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt

这是错误堆栈:

    Proguard returned with error code 1. See console
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find superclass or interface java.awt.datatransfer.Transferable
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.NativeClipboard: can't find superclass or interface java.awt.datatransfer.Clipboard
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.Sasl
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator: can't find referenced class javax.security.sasl.SaslClient
    [2013-08-28 18:27:13 - MyApp] Warning: com.sun.mail.imap.protocol.IMAPSaslAuthenticator$1: can't find referenced class javax.security.sasl.RealmChoiceCallback
    [2013-08-28 18:27:13 - MyApp] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-08-28 18:27:13 - MyApp] Warning: javax.activation.CommandInfo: can't find referenced class java.beans.Beans
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.Toolkit
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.ContextStorage: can't find referenced class java.awt.GraphicsEnvironment
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DTK: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProvider: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProvider: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProvider: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProvider: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.Transferable
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.UnsupportedFlavorException
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataSnapshot: can't find referenced class java.awt.datatransfer.SystemFlavorMap
    [2013-08-28 18:27:13 - MyApp] Warning: org.apache.harmony.awt.datatransfer.DataSource: can't find referenced class java.awt.datatransfer.DataFlavor
    [2013-08-28 18:27:13 - MyApp] Warning: there were 247 unresolved references to classes or interfaces.
    [2013-08-28 18:27:13 - MyApp]          You may need to specify additional library jars (using '-libraryjars').
    [2013-08-28 18:27:13 - MyApp] java.io.IOException: Please correct the above warnings first.
    [2013-08-28 18:27:13 - MyApp]   at proguard.Initializer.execute(Initializer.java:321)
    [2013-08-28 18:27:13 - MyApp]   at proguard.ProGuard.initialize(ProGuard.java:211)
    [2013-08-28 18:27:13 - MyApp]   at proguard.ProGuard.execute(ProGuard.java:86)
    [2013-08-28 18:27:13 - MyApp]   at proguard.ProGuard.main(ProGuard.java:492)

6 个答案:

答案 0 :(得分:15)

将这些行添加到proguard配置文件(proguard-android.txt)

    -keep class android.support.v4.** { *; }   
    -dontwarn android.support.v4.**
    -dontwarn javax.activation.**
    -dontwarn javax.security.**
    -dontwarn java.awt.**
    -libraryjars <java.home>/lib/rt.jar
    -keep class javax.** {*;}
    -keep class com.sun.** {*;}
    -keep class myjava.** {*;}
    -keep class org.apache.harmony.** {*;}
    -keep public class Mail {*;}        
    -dontshrink

请参阅Proguard Troubleshooting

请注意,如果您使用

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt

您的配置文件不是项目根目录中的proguard-android.txt,而是android sdk文件夹中的常规proguard配置文件。 如果要在项目根目录中使用proguard-android.txt,则必须使用

proguard.config=proguard-project.txt
在project.properties文件中

答案 1 :(得分:3)

(CFR)。 ProGuard手册&gt;疑难解答&gt; Warning: can't find referenced class

Android SDK中不存在AWT类。 ProGuard会看到一些依赖于它们的类并对它们发出警告,就像编译器一样。由于这些类可能从未真正使用过,因此您可以告诉ProGuard忽略它:

-dontwarn java.awt.**
然后,ProGuard将继续处理代码。你不应该添加任何-libraryjars选项。

答案 2 :(得分:1)

在你的错误堆栈中,在底部,注意不要“指定额外的罐子......”

检查你的proguard配置是否包含android jar,其中包括所有引用的缺失包,如'javax'和'awt'enter code here

尝试在proguard.cfg中添加以下内容......

-libraryjars  /usr/local/src/android-sdk-linux/platforms/android-18/android.jar
-libraryjars <java.home>/lib/rt.jar

答案 3 :(得分:0)

通过此链接将您的progaurd更新到最新版本4.10

http://sourceforge.net/projects/proguard/files/proguard/4.10/

解压缩文件并替换android sdk目录中的内容(tools目录中的progaud文件夹)

[android sdk的路径] \ Android \ android-sdk \ tools \ proguard

然后再试一次,你可能需要重启eclipse。

答案 4 :(得分:0)

我在以下过程中成功忽略了eclipse中的无效包错误:

右键点击项目&gt;属性&gt; android lint reference&gt;在搜索行中输入&#34;无效&#34; &GT;并标记id = InvalidPackage&gt;并在右下角更改严重性以忽略。

enter image description here

注意,这是一个肮脏的解决方法(我无法让proguard忽略所以......)

祝你好运!

答案 5 :(得分:0)

我在日食中遇到了同样的问题。我可以通过添加

解决它

-ignorewarnings

在progaurd-project.txt