定义了多个DEX文件 - Android的摇篮DexException [英] Android Gradle DexException - Multiple dex files defined
问题描述
com.android.dex.DexException:多DEX文件定义Lorg / hamcrest /说明的
发生在试图做一个调试版本/测试或者通过 Android的工作室或通过摇篮在我的应用程序的命令行。
发布版本(没有测试)工作正常,但只要测试包括( hamcrest
是一个测试库),生成失败并出现上述错误。
我检查了我的模块依赖关系,并有其摇篮-q依存关系没有重复的要求证实。
项目settings.gradle 的
包括':库模块]
包括':[主模块]
项目build.gradle 的
buildscript {
库{
mavenCentral()
}
依赖{
类路径com.android.tools.build:gradle:0.9.+
类路径org.robolectric.gradle:摇篮,Android的测试插件:0.9 +
}
}
allprojects {
库{
mavenCentral()
}
}
[库模块] build.gradle 的
应用插件:机器人库
安卓{
compileSdkVersion 19
buildToolsVersion19.0.0
defaultConfig {
的minSdkVersion 14
targetSdkVersion 19
}
packagingOptions {
不包括META-INF / LICENSE.TXT
不包括META-INF / NOTICE.txt
}
}
依赖{
编译com.google.zxing:核心:3.0 +
编译com.bugsnag:bugsnag-机器人:2.1.1+
}
[主模块] build.gradle 的
应用插件:'机器人'
安卓{
signingConfigs {
推出 {
[...]
}
}
sourceSets {
主要 {
manifest.srcFile钢骨混凝土/主/ AndroidManifest.xml中
res.srcDirs = ['钢骨混凝土/主/ RES']
}
androidTest {
setRoot(SRC /测试)
}
instrumentTest {
}
}
compileSdkVersion 19
buildToolsVersion '19 .0.0
defaultConfig {
的minSdkVersion 14
targetSdkVersion 19
testPackageName[main.packageName] .tests
}
buildTypes {
推出 {
runProguard假
proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'ProGuard的-rules.txt
}
}
packagingOptions {
不包括META-INF / LICENSE.TXT
不包括META-INF / NOTICE.txt
}
}
应用插件:Android的测试
androidTest {
//配置集合类JUnit测试
包括** / * Test.class
//配置测试JVM的最大堆大小
maxHeapSize =2048米
}
库{
行家{URLhttps://repo.commonsware.com.s3.amazonaws.com'}
行家{URLhttps://oss.sonatype.org/content/repositories/snapshots/'}
}
依赖{
androidTestCompile'的JUnit:JUnit的:4.10
androidTestCompileorg.robolectric:robolectric:2.3快照
androidTestCompilecom.squareup:巨星 - 安卓1.0 +
编制项目(':库模块])
编译com.github.gabrielemariotti.changeloglib:图书馆:1.4 +。
编译com.google code.gson:GSON:2.2.4
编译com.google.android.gms:播放服务:+
编译com.android.support:appcompat-v7:+
编译(de.keyboardsurfer.android.widget:crouton:1.8 +'){
排除组:com.google.android',模块:支持-V4
}
编译文件(库/ CWAC-LoaderEx.jar)
编译com.squareup.okhttp:okhttp:1.5 +。
编译com.octo.android.robospice:robospice:1.4.11
编译com.octo.android.robospice:robospice缓存:1.4.11
编译com.octo.android.robospice:robospice-改造:1.4.11
编译com.commonsware.cwac:安全性:0.1 +。
编译com.readystatesoftware.sqliteasset:sqliteassethelper:+
}
Robolectric 2.3依赖于JUnit的4.8.1(版本明确)。要导入的JUnit 4.10(版本明确)。 Hamcrest可能只是很多重复地塞米松是窒息的第一 - 尝试(从Robolectric依赖或排除的JUnit)改变您的JUnit要求版本4.8+
com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/Description
occurring while trying to do a debug build/test either via Android Studio or via Gradle command-line on my application.
The release build (without tests) works fine but as soon as testing is included (hamcrest
being a testing library), the build fails with the above error.
I've checked my module dependencies and there's no duplicate requirements which gradle -q dependencies corroborates.
Project settings.gradle
include ':[library module]'
include ':[main module]'
Project build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
[library module] build.gradle
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.google.zxing:core:3.0.+'
compile 'com.bugsnag:bugsnag-android:2.1.1+'
}
[main module] build.gradle
apply plugin: 'android'
android {
signingConfigs {
release {
[...]
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['src/main/res']
}
androidTest {
setRoot('src/test')
}
instrumentTest {
}
}
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
testPackageName "[main.packageName].tests"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
apply plugin: 'android-test'
androidTest {
// configure the set of classes for JUnit tests
include '**/*Test.class'
// configure max heap size of the test JVM
maxHeapSize = "2048m"
}
repositories {
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
androidTestCompile 'junit:junit:4.10'
androidTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
androidTestCompile 'com.squareup:fest-android:1.0.+'
compile project(':[library module]')
compile 'com.github.gabrielemariotti.changeloglib:library:1.4.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:+'
compile ('de.keyboardsurfer.android.widget:crouton:1.8.+') {
exclude group: 'com.google.android', module: 'support-v4'
}
compile files('libs/CWAC-LoaderEx.jar')
compile 'com.squareup.okhttp:okhttp:1.5.+'
compile 'com.octo.android.robospice:robospice:1.4.11'
compile 'com.octo.android.robospice:robospice-cache:1.4.11'
compile 'com.octo.android.robospice:robospice-retrofit:1.4.11'
compile 'com.commonsware.cwac:security:0.1.+'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
}
Robolectric 2.3 depends on JUnit 4.8.1 (version explicit). You're importing JUnit 4.10 (version explicit). Hamcrest is probably simply the first of many duplicates that dex is choking on - try changing your JUnit requirement version to 4.8+ (or excluding JUnit from the Robolectric dependency).
这篇关于定义了多个DEX文件 - Android的摇篮DexException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!