我的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.10.0'
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'android'
apply plugin: 'spoon'
apply plugin: 'robolectric'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
testInstrumentationRunner 'com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner'
}
buildTypes {
debug {
}
release {
}
}
productFlavors {
first {
//just version codes and packages
}
second {
//just version codes and packages
}
third {
//just version codes and packages
}
}
}
spoon {
debug = true
}
dependencies {
compile project(':app:libs:facebookSDK')
compile 'com.google.android.gms:play-services:5.0.89'
compile 'com.android.support:support-v4:20.0.0+'
compile 'com.google.code.gson:gson:2.2.4'
compile fileTree(dir: 'libs', include: '*.jar')
androidTestCompile fileTree(dir: 'libsTest', include: '*.jar')
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.0'
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'org.robolectric:robolectric:2.3'
}
libsTest:意式浓缩咖啡-1.1-bundled.jar
现在,我的错误如下:
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/SelfDescribing;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
在这里可以获得更详细的日志:
http://pastebin.com/Yye3cd1c
我该如何解决这个问题?
UPD:我现在的问题基本上是我如何寻找那些复制的部件?
发布于 2014-10-21 10:46:19
我现在的问题基本上是我如何去寻找那些复制的部分?
你用日志来做这件事。你粘贴的原木上写着:
com.android.dex.DexException:多个dex文件定义
这很可能是由于冲突的库造成的。日志继续如下:
罗格/哈姆克里斯特/自我描述;
下面是冲突库hamcrest。
将依赖项添加到项目后,如果库(或作为库)使用公共子库,则会发生此错误。因此,似乎汉克雷斯特不仅仅是你的一个库所使用的。
我们将通过检查依赖关系来了解这种冲突。当然,有效的检查同时需要直觉和理性。
让我们从汉克莱斯特开始吧。(我想你以前没听说过汉克雷斯特吧。)
让我们来看看Hamcrest项目页面。Hamcrest将自己定义为用于构建测试表达式的匹配器库。定义说典型的场景包括测试框架,模拟库.这很有启发性,因为您对测试有一些依赖关系,比如JUnit、Espresso和Robolectric。
现在我们应该继续使用JUnit 依赖关系。JUnit似乎利用了hamcrest。这里是我们作为子依赖的第一个汉克雷斯特。
让我们继续使用Espresso,因为espresso-contrib-1.1-bundled.jar
在libsTest
文件夹中。当我们查看浓缩咖啡项目依赖关系时,我们可以看到Espresso大量使用了hamcrest。
我们可能在您的项目中得到了冲突的库,最后一步是在添加此依赖项的同时将hamcrest-core
从我们的依赖项中排除在外。您可以通过以下方式实现这一点:
androidTestCompile('junit:junit:4.+') {
exclude module: 'hamcrest-core'
}
发布于 2014-10-14 13:46:51
不久前我也有类似的问题,如果我没记错的话,我就添加了一条排除语句,如下所示:
androidTestCompile('junit:junit:4.+') {
exclude module: 'hamcrest-core'
}
发布于 2014-10-15 09:31:15
受deckard-分级示例项目的启发,我建议尝试这样的方法:
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
https://stackoverflow.com/questions/26275282
复制相似问题