我正在尝试像这篇文章中那样发送一封电子邮件: Sending Email in Android using JavaMail API without using the default/built-in app
并在我的 build.gradle 和应用程序文件中添加以下行:https://javaee.github.io/javamail/Android
错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/sun/activation/registries/LineTokenizer;
但是对于以下应用程序文件,我执行失败并且不知道为什么。
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'
这是我的项目 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 的新手。
最佳答案
这个错误非常棘手。我也很难过。我通过在我的 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。
关于java - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' . 尝试发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45009154/