0

i create a send email application with android studio, i use javamail to send email, but when i try to build and debug the application there is error like this

Error:FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/mailcap
    File1: C:\AndroidStudio\CobaEmailGuard\app\libs\dsn.jar
    File2: C:\AndroidStudio\CobaEmailGuard\app\libs\mail.jar
    File3: C:\AndroidStudio\CobaEmailGuard\app\libs\mailapi.jar

this is my build.grandle(module:app)

apply plugin: 'com.android.application'


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile files('libs/mail.jar')
}

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.example.eladoktarizo.cobaemailguard"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
    }
}

whether the error in grandle or misplaced jars files?

1 Answers1

0

You do not need both mail.jar and mailapi.jar, as described in the JavaMail NOTES.txt file; just use mail.jar. The JavaMail Android page also has a gradle build example.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40