Cannot fix Android Proguard Returned with error co

2019-04-07 07:17发布

When I try to use proguard in my android application simply adding

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

to my project.properties file, the APK export fails with the message Proguard Returned with error code 1

This is my project.properties file

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

This is the error stack:

    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条回答
疯言疯语
2楼-- · 2019-04-07 07:20

I've successfully ignored the invalid package errors in eclipse in the following procedure:

right click on the project > Properties > android lint reference > in the search line type "invalid" > and mark the id = InvalidPackage > and on the lower right change severity to ignore.

enter image description here

Note, its a dirty workaround (I could not make the proguard ignore so...)

good luck!

查看更多
孤傲高冷的网名
3楼-- · 2019-04-07 07:29

in your error stack, at the bottom, pay attention to not on 'specify additional jars...'

Review your proguard config for inclusion of the android jar which includes all the referenced missing packages like 'javax' and 'awt' enter code here

try adding something like following to your proguard.cfg...

-libraryjars  /usr/local/src/android-sdk-linux/platforms/android-18/android.jar
-libraryjars <java.home>/lib/rt.jar
查看更多
看我几分像从前
4楼-- · 2019-04-07 07:32

Cfr. ProGuard manual > Troubleshooting > Warning: can't find referenced class

The AWT classes are not present in the Android SDK. ProGuard sees some classes that depend on them and warns about them, just like a compiler would do. Since the classes presumably are never really used, you can tell ProGuard to ignore it:

-dontwarn java.awt.**

ProGuard will then proceed processing the code. You shouldn't add any -libraryjars options.

查看更多
家丑人穷心不美
5楼-- · 2019-04-07 07:35

Add these lines to proguard config file (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

See Proguard Troubleshooting

Note that if you use

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

Your config file isn't the proguard-android.txt in your project root but the general proguard config file in the android sdk folder. If you want to use the proguard-android.txtin your project root you have to use

proguard.config=proguard-project.txt

in project.properties file.

查看更多
我想做一个坏孩纸
6楼-- · 2019-04-07 07:37

I had the same problem in eclipse. I could resolve it by adding

-ignorewarnings

in the progaurd-project.txt

查看更多
做自己的国王
7楼-- · 2019-04-07 07:40

update your progaurd to the latest version 4.10 from this link

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

unzip the file and replace the content in your android sdk directory (progaud folder in tools directory)

[path to android sdk] \Android\android-sdk\tools\proguard

then try again, you might need to restart eclipse.

查看更多
登录 后发表回答