Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Gradle: error: package javax.mail does not exist

How can I get the .jar files from javamail to work?

I'm using intelliJ IDEA IDE and tried going to project structure - libraries - add - located .jar files and saved. I then went to modules and checked the boxes under exports simply because the support library I use for fragments, etc was checked as well.

I used the code from Sending Email in Android using JavaMail API without using the default/built-in app but no luck.

I tried using the .jar files intact as well as after extraction but both failed with same error.

I'm not getting an error while in edit mode for code, only when compiling does the gradle build fail and present me with error, "Error(3,6): Gradle: error: package javax.mail does not exist. Please help!

I also tried to follow instructions on How can I use external JARs in an Android project? but I think that directions pertain to eclipse IDE instead.

edt: gradle-build:

Information:Compilation completed with 25 errors and 0 warnings in 25 sec
Information:25 errors
Information:0 warnings
Error:Gradle: Execution failed for task ':app:compileDebugJava'.

Compilation failed; see the compiler error output for details. C:\Users\Marcus\Documents\IdeaProjects\Android\TestProjects\TestMailFeature3\app\src\main\java\com\majorwit\testmailfeature3\app\GMailSender.java

Error:(3, 24) Gradle: error: package javax.activation does not exist

Error:(4, 24) Gradle: error: package javax.activation does not exist

Error:(5, 18) Gradle: error: package javax.mail does not exist

Error:(6, 18) Gradle: error: package javax.mail does not exist

Error:(7, 18) Gradle: error: package javax.mail does not exist

Error:(8, 18) Gradle: error: package javax.mail does not exist

Error:(9, 27) Gradle: error: package javax.mail.internet does not exist

Error:(10, 27) Gradle: error: package javax.mail.internet does not exist

Error:(18, 44) Gradle: error: package javax.mail does not exist

Error:(22, 13) Gradle: error: cannot find symbol class Session

Error:(46, 15) Gradle: error: cannot find symbol class PasswordAuthentication

Error:(67, 49) Gradle: error: cannot find symbol class DataSource    

Error:(43, 19) Gradle: error: cannot find symbol variable Session

Error:(47, 20) Gradle: error: cannot find symbol class PasswordAuthentication

Error:(52, 13) Gradle: error: cannot find symbol class MimeMessage

Error:(52, 39) Gradle: error: cannot find symbol class MimeMessage

Error:(53, 13) Gradle: error: cannot find symbol class DataHandler

Error:(53, 39) Gradle: error: cannot find symbol class DataHandler

Error:(54, 35) Gradle: error: cannot find symbol class InternetAddress

Error:(58, 46) Gradle: error: package Message does not exist

Error:(58, 65) Gradle: error: cannot find symbol variable InternetAddress

Error:(60, 45) Gradle: error: package Message does not exist

Error:(60, 68) Gradle: error: cannot find symbol class InternetAddress

Error:(61, 13) Gradle: error: cannot find symbol variable Transport
like image 626
cjayem13 Avatar asked Nov 01 '22 19:11

cjayem13


1 Answers

The javax.activation and javax.mail packages are not part of the standard android packages (http://developer.android.com/reference/packages.html).

Fortunately an Android version has of JavaMail been released (https://java.net/projects/javamail/pages/Android). I followed the suggestion of modifying the build.gradle file for my project in Android Studio and was able to successfully compile without having to manually download any jar files.

android {
  packagingOptions {
    pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
  }
}
repositories { 
  jcenter()
  maven {
    url "https://maven.java.net/content/groups/public/"
  }
} 
dependencies {
  compile 'com.sun.mail:android-mail:1.5.5'
  compile 'com.sun.mail:android-activation:1.5.5'
}
like image 100
user1661191 Avatar answered Nov 09 '22 07:11

user1661191