Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Proguard and Javamail

First off, i've already to referred to a similar post, Android, javamail and proguard

The solution mentioned was to explicitly keep 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 sight, this seemed to work, as it compiled without any warnings. However, it fails at reading the message content and just skips right over it. I've tried the following:

  1. -includelibraryjars explicitly naming the 3 jar files required for javamail.
  2. -removed the jars as an external library, following the new libs/ include format.
  3. -maintained the default android settings in proguard-android.txt
  4. -followed the troubleshooting guide in the proguard faq.
  5. -started a new project and copied over the source files to it.
  6. -tried various proguard options, including -dontshrink, keepnames, etc
  7. -obsessive project/clean

After a few hours of frustration, here's 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 that's absurd because i'm turning on -dontobfuscate and -dontshrink. Any proguard and javamail gurus have a solution to this? I'm ADT17, using 2.1(api7) for the build. If i could exclude the jars entirely from the process maybe? Any advice will be a godsend at this point.

like image 589
ThumbsDP Avatar asked Jun 01 '12 12:06

ThumbsDP


1 Answers

Problem solved. I've posted the solution here for anyone having issues with the other solution mentioned in the link above.

Because i was using a helper class with javamail (Mail.java), i needed to include that class as a -keep so that it would work. I edited the solution provided at Android, javamail and proguard to include the helper class, since many use this and the other solution may fail horribly without it.

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

-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.**
like image 191
ThumbsDP Avatar answered Oct 10 '22 03:10

ThumbsDP