I am trying to use javamail in my Android app, but proguard complains about a whole load of stuff that it cannot find. I have tried various remedies that I have found while searching the internet, but nothing seems to work. Has anyone got this thing working? Thanks.
I have added some -dontwarn commands to the defauly proguard.cfg, and succeeded in eliminating all of the warning messages except this one:
Warning: org.apache.harmony.awt.datatransfer.DataProxy: can't find referenced class [Ljava.awt.datatransfer.DataFlavor;
This warning is not even in the same format as all the others.
I am using the 2.1 SDK, which might make a difference. I also have a fairly complex email. But I have sorted it now, by upgrading to proguard 4.6 and adding the following lines to my proguard,cfg:
-dontwarn java.awt.**
-dontwarn java.beans.Beans
-dontwarn javax.security.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.dsn.** {*;}
-keep class com.sun.mail.handlers.** {*;}
-keep class com.sun.mail.smtp.** {*;}
-keep class com.sun.mail.util.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}
The last group of lines is non-trivial. I obtained it by running tar tf commands against each of the jars in the javamail package.
Update for SDK 17
Android SDK 17 introduces some changes in the way that jars are loaded. If you have a project that uses external jars, upgrading to SDK 17 or beyond will probably break it. To fix this, select Project > Properties > Java Build Path > Order and Export from the menu, and check the boxes to left of the three jars used by javamail. This ensures that the jars get exported to the target build. Without this fix, the project will still build, but javamail will no longer work and proguard will also fail. This is not a proguard issue at all. It is an Android SDK issue. No changes to proguard.cfg are required.
Another consequence of upgrading the SDK is that it is no longer necessary to upgrade proguard manually.
Cfr. ProGuard manual > Troubleshooting > Warning: can't find superclass or interface.
More detailed similar questions and answers today: one on stackoverflow and one in ProGuard's help forum.
The garbled error message "[Ljava.awt.datatransfer.DataFlavor;" has been solved in ProGuard 4.6. You can simply replace proguard.jar in the Android SDK. Alternatively, you can work around the problem by listing the referencing class instead of the referenced class: "-dontwarn org.apache.harmony.awt.datatransfer.DataProxy".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With