7

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.

Philip Sheard
  • 5,789
  • 5
  • 27
  • 42
  • I've had problems with Proguard in the past, but I can't really help unless you can be more specific. Can you post the error message or any other additional information you have? – Joe Krill Mar 25 '11 at 16:10
  • That would be difficult. There are 247 error messages, and the output exceeds the size limit for a question. – Philip Sheard Mar 25 '11 at 19:23
  • Are you able to determine which lines may be relevant? Or, you can use [gist](https://gist.github.com/) or [pastebin](http://pastebin.com/) to post the full data. – Joe Krill Mar 25 '11 at 20:13

3 Answers3

23

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.

Philip Sheard
  • 5,789
  • 5
  • 27
  • 42
  • Just tried it and this fix is required for the 2.3 SDK too :-( – tonys Mar 26 '11 at 15:37
  • @philip : Thanks sir its helpful for me & now working javamail in my project – Deepanker Chaudhary Jun 03 '13 at 07:14
  • Thank you! Used several approaches to no avail (i.e. -libraryjars /lib/rt.jar(java/**,javax/security/**,javax/activation/**,org/ietf/jgss/**) was generating a working .apk but the actual email functionality in it failed miserably. – halxinate Aug 10 '13 at 00:34
  • 1
    This solution allows compilation, but break email functionality (at least for me) :/ This one is OK: http://stackoverflow.com/questions/10850304/android-proguard-and-javamail – Pascal Feb 29 '16 at 13:46
1

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".

Community
  • 1
  • 1
Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • Need to do these steps in order to use the "checked" solution if you are using an older version of Proguard (pre-4.6). Check proguard version: http://stackoverflow.com/questions/5013163/how-can-i-check-upgrade-proguard-version-whn-using-it-in-eclipse-for-android-dev – amit Jul 01 '12 at 02:44
0

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

tonys
  • 3,855
  • 33
  • 39
  • I used this code as a starting point in my own app, and I had no problems until I tried to export an apk. – Philip Sheard Mar 26 '11 at 13:49
  • **Caution:** This javamail-android library has a GPL license, which means you can't use in in a commercial app without open sourcing your app as well. – ehartwell May 16 '16 at 01:38