3

I am getting this error after trying to generate my apk

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

i can run my code to a device but not generating an APK

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Hicham Bagui
  • 240
  • 1
  • 17

2 Answers2

4

Try to add this in the Proguard part of the gradle file:

-dontwarn java.awt.**,javax.activation.**,java.beans.**
Jaythaking
  • 2,200
  • 4
  • 25
  • 67
  • This merely hides the Proguard warning - and does NOT FIX the underlying problem. See [this SO post](https://stackoverflow.com/questions/10850304/android-proguard-and-javamail) for clarity on this issue - that is if you got this error while trying to use the JAVA Mail API. – SilSur Aug 19 '17 at 20:13
1

As @SilSur comments, the chosen solution only hides the Proguard warning but doesn't prevent runtime errors due to missing classes. After some trial-error I found that this Proguard configuration works OK preventing any runtime problems:

# JavaMail
-dontwarn java.awt.**
-dontwarn javax.activation.**
-dontwarn java.beans.**
-keep class javamail.** {*;}
-keep class javax.mail.** {*;}
-keep class javax.activation.** {*;}
-keep class com.sun.mail.** {*;}
-keep class mailcap.** {*;}
-keep class mimetypes.** {*;}
-keep class myjava.awt.datatransfer.** {*;}
-keep class org.apache.harmony.awt.** {*;}
-keep class org.apache.harmony.misc.** {*;}