问题
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)
回答1:
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.
回答2:
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.
回答3:
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:
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.
回答5:
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.
Note, its a dirty workaround (I could not make the proguard ignore so...)
good luck!
回答6:
I had the same problem in eclipse. I could resolve it by adding
-ignorewarnings
in the progaurd-project.txt
来源:https://stackoverflow.com/questions/18493608/cannot-fix-android-proguard-returned-with-error-code-1-error