错误:任务':app:transformClassesWithDexForDebug'的执行失败。尝试发送电子邮件

时间:2017-07-10 10:02:22

标签: java android javamail project

我正在尝试发送此帖子中的电子邮件: Sending Email in Android using JavaMail API without using the default/built-in app

在我的build.gradle和app文件中添加以下行:https://javaee.github.io/javamail/Android

错误:

  

错误:任务执行失败   ':应用程序:transformClassesWithDexForDebug'。 >   com.android.build.api.transform.TransformException:   com.android.ide.common.process.ProcessException:   java.util.concurrent.ExecutionException:com.android.dex.DexException:   多个dex文件定义   LCOM /太阳/激活/注册/ LineTokenizer;

但是使用以下app文件我执行失败并且不知道原因。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.github.ocaparrostortosa.MyApplication"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
    }
}

dependencies {
    compile 'com.sun.mail:android-mail:1.5.5'
    compile 'com.sun.mail:android-activation:1.5.5'
    compile 'com.google.firebase:firebase-core:10.2.1'
    compile 'com.google.firebase:firebase-database:10.2.1'
    compile 'com.google.firebase:firebase-auth:10.2.1'
    compile 'com.google.android.gms:play-services-auth:10.2.1'
    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:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

这个是我的Project gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.java.net/content/groups/public/"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
是的,有人能帮帮我吗?我即将完成项目:D

P.D:对不起我的英语和演示文稿,我是stackoverflow的新手。

1 个答案:

答案 0 :(得分:2)

这个错误非常棘手。我也很难过。我通过在gradle build.config

上添加multiDexEnabled true以某种方式解决了我的问题
android {
     defaultConfig {
         minSdkVersion 14 x
         targetSdkVersion 23
         multiDexEnabled true
     }
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
}

请注意,此解决方案是个案基础。 一种情况是 - 我的应用程序非常大,超过64MB限制。如果这不起作用,请检查您的依赖项。

其他情况是由Google Maps API依赖项导致的,该版本需要与APP目标SDK内联。