7

当我尝试在我的 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)
4

6 回答 6

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 故障排除

请注意,如果您使用

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 文件中。

于 2013-08-29T11:24:03.307 回答
3

参照。ProGuard 手册 > 疑难解答 >警告:找不到引用的类

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

-dontwarn java.awt.**

ProGuard 将继续处理代码。您不应该添加任何 -libraryjars 选项。

于 2013-08-29T23:31:02.760 回答
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
于 2013-08-28T17:06:28.323 回答
0

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

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

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

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

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

于 2013-08-28T16:58:10.980 回答
0

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

右键单击项目 > 属性 > android lint 参考 > 在搜索行类型“无效” > 并标记 id = InvalidPackage > 并在右下角更改严重性以忽略。

在此处输入图像描述

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

祝你好运!

于 2015-10-25T08:50:31.763 回答
0

我在eclipse中遇到了同样的问题。我可以通过添加来解决它

-ignorewarnings

在 progaurd-project.txt

于 2018-03-09T09:19:35.800 回答