开发者

Android, javamail and proguard

I am trying to use javamail in my Andr开发者_运维百科oid 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".


Are you using this project: javamail-android ?

It worked for me without a single hitch (admittedly using the default Proguard settings in the 2.3 SDK) so the problem might be that the standard javamail requires AWT classes that aren't present in Android.

The associated sample code is at Sending Emails without User Intervention (no Intents) in Android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜