java.lang.NoClassDefFoundError: javax.activation.DataHandler in android-ThrowExceptions

Exception or error:

I am making a email sending application in android phone. For that I included two jar file activation. jar and mail.jar. But when I run this application and try to send the mail, I got following error on LogCat.

java.lang.NoClassDefFoundError: javax.activation.DataHandler 

I am new to android. so I am not able to figure out this issue. please Help me. Thanks

How to solve:

There is an Android-friendly port of javamail which you should be using. There are three libraries that you need to include in your app: mail.jar, activation.jar, and additionnal.jar(sic). It looks like you are missing something that the activation library depends on, and this could be because you are not using the Android port of this library.

I have used the Android-friendly version of javamail successfully in a project, and it works really well.


The JavaMail API Reference Implementation version 1.5.5 and later have built in support for Android and include support for OAuth2.

Per the documentation:

Android does not provide a Java Compatible runtime and so can’t run the standard JavaMail distribution. Instead, a special version of JavaMail is available for Android. This special version of JavaMail depends on a special version of the JavaBeans Activation Framework.

You can try out this version by adding the following to your build.gradle file for your Android application:

 android {
     packagingOptions {
         pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file

 repositories { 
     maven {
         url ""

 dependencies {
     compile 'com.sun.mail:android-mail:1.5.5'
     compile 'com.sun.mail:android-activation:1.5.5'

Starting with JavaMail 1.6.0:

JavaMail for Android requires at least Android API level 19, which corresponds to Android KitKat, currently the oldest supported version of Android.

Leave a Reply

Your email address will not be published. Required fields are marked *