Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot fix Android Proguard Returned with error code 1 error

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)
like image 333
AndreaF Avatar asked Aug 28 '13 16:08

AndreaF


2 Answers

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.

like image 120
Silverstorm Avatar answered Oct 13 '22 18:10

Silverstorm


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.

like image 39
Eric Lafortune Avatar answered Oct 13 '22 16:10

Eric Lafortune