Android, Proguard and Javamail

Firstly, I already mentioned a similar post, Android, javamail and proguard

The decision was made to explicitly save the following in proguard-project.txt:

-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.** {*;} 

At first glance, this seemed to work, as it was compiled without any warning. However, it does not read the contents of the message and simply skips it. I tried the following:

  • -includelibraryjars explicitly names the 3 jar files needed for javamail.
  • - freed banks as an external library, following the new libs / include format.
  • -Got the default android settings in proguard-android.txt
  • - Followed the troubleshooting guide for the proguard faq file.
  • - launched a new project and copied it to the source files.
  • -tried various proguard options, including -dontshrink, keepnames, etc.
  • -objective project / clean

After hours of disappointment, here is what I found that seemed to work:

 -dontobfuscate -dontshrink -keepdirectories -keeppackagenames javax.mail.** -keeppackagenames javax.activation.** -keeppackagenames com.sun.mail.** -keeppackagenames myjava.** -keeppackagenames org.apache.harmony.** -keeppackagenames mailcap.** -keeppackagenames mimetypes.** -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.** {*;} -dontwarn java.awt.** -dontwarn java.beans.Beans -dontwarn javax.security.** 

Of course, this is absurd, because I include -dontobfuscate and -dontshrink. Does any protector and javal guru have a solution? I am ADT17 using 2.1 (api7) for build. If I could completely eliminate banks from the process? At the moment, any advice would be a godsend.

+3
source share
2 answers

The problem is resolved. I posted the solution here for those who have problems with the other solution mentioned in the link above.

Since I used a helper class with javamail (Mail.java), I needed to include this class as -keep for it to work. I edited the solution presented in Android, javamail and proguard to include a helper class, as many use this, and another solution may fail without it.

Put this in your proguard-project.txt file. Otherwise, I used the default android settings.

 -dontshrink -keep class javax.** {*;} -keep class com.sun.** {*;} -keep class myjava.** {*;} -keep class org.apache.harmony.** {*;} -keep public class Mail {*;} -dontwarn java.awt.** -dontwarn java.beans.Beans -dontwarn javax.security.** 
+9
source

In my case, javax.activation caused the following problem:

 Warning: com.sun.mail.handlers.handler_base: can't find referenced method 'boolean equals(java.awt.datatransfer.DataFlavor)' in program class javax.activation.ActivationDataFlavor 

So I had to add -dontwarn javax.activation.** to the ThumbsDP solution. So, collectively, the following additions to the proguard rules that helped me:

 -dontshrink -keep class javax.** {*;} -keep class com.sun.** {*;} -keep class myjava.** {*;} -keep class org.apache.harmony.** {*;} -keep public class Mail {*;} -dontwarn java.awt.** -dontwarn java.beans.Beans -dontwarn javax.security.** -dontwarn javax.activation.** 
0
source

All Articles