感觉我什么都试过了。每次我让导入在没有任何编译器错误的情况下工作时,都会丢失一些类。我进口了,所以除了PowerMockRunner.class
我什么都有我不知道如果没有它,我将如何使用powerMock
这是我的等级文件,现在看起来像
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services_lib')
compile project(':facebook-sdk_lib')
compile 'de.greenrobot:greendao:1.3.7'
compile ('com.google.dexmaker:dexmaker:1.1')
compile ('com.google.dexmaker:dexmaker-mockito:1.1'){
exclude group: 'org.hamcrest'
exclude group: 'org.javassist'
}
compile('junit:junit:4.4'){
exclude group: 'org.hamcrest'
}
compile('org.mockito:mockito-core:1.9.5'){
exclude group: 'org.hamcrest'
}
compile('org.powermock:powermock-api-mockito:1.4.12'){
exclude group: 'org.hamcrest'
}
}
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
compileSdkVersion 19
buildToolsVersion "19.1.0"
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java {
srcDir 'src'
srcDir 'src-gen'
srcDir 'tests'
}
resources {
srcDir 'src'
srcDir 'src-gen'
}
aidl.srcDirs = ['src','src-gen']
renderscript.srcDirs = ['src','src-gen']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
这是一个编译器错误,我整天都被抛在脸上。
意外的顶级异常:com.android.dex.DexException:多个dex文件定义Lorg/hamcrest/Description;网址:com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)网址:com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)网址:com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)网址:com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)网址:com.android.dx.merge.DexMerger.merge(DexMerger.java:188)网址:com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)网址:com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)在com.android.dx.command.dexer.Main.run(Main.java:230)网址:com.android.dx.command.dexer.Main.Main(Main.java:199)在com.android.dx.command.Main.Main(Main.java:103)
昨天我坐了一整天,想知道如何解决这个问题。现在它已经解决了,这就是我对gradle.build
文件所做的,以修复问题
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services_lib')
compile project(':facebook-sdk_lib')
compile ('de.greenrobot:greendao:1.3.7'){
exclude group: 'org.hamcrest'
}
androidTestCompile('org.mockito:mockito-core:1.9.5'){
exclude group: 'org.hamcrest'
}
androidTestCompile('org.powermock:powermock-module-junit4:1.5'){
exclude group: 'org.hamcrest'
}
}
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
compileSdkVersion 19
buildToolsVersion "19.1.0"
lintOptions {
abortOnError false
}
sourceSets {
main
{
manifest.srcFile 'AndroidManifest.xml'
resources
{
srcDir 'src-gen'
}
aidl.srcDirs = ['src/main/java', 'src-gen']
renderscript.srcDirs = ['src/main/java', 'src-gen']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
java.srcDirs = ['src/main/java', 'src/main/java/', 'src-gen']
}
androidTest {
java.srcDirs = ['tests']
}
unitTest {
java.srcDir file('tests')
resources.srcDir file('tests/res')
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}//-End of sourceSet
} //-End of android
希望这能帮助至少一个人不要陷入我经历的同样的等级失败循环。