Android, javamail and proguard

时间秒杀一切 提交于 2019-11-28 10:16:17

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.

Eric Lafortune

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!