the*_*ger 8 android unit-testing
我有一个应用程序,我有本地单元测试(测试文件夹)和仪表单元测试用例(androidTest文件夹).现在,如果我点击androidTest文件夹,然后单击" 运行所有测试 ",它将抛出以下异常.
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexIndexOverflowException: field ID not in [0, 0xffff]: 65536
Error:Execution failed for task ':news-app:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
Run Code Online (Sandbox Code Playgroud)
这个例外显然是因为达到了multidex限制.但我启用multi-dex了调试版本.我想当运行检测测试用例时,它们以调试模式运行.那为什么会发生这种异常呢?
我附加了build.gradle文件
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 22
buildToolsVersion 22.0.1
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
applicationId "com.xyz"
}
buildTypes {
debug {
minifyEnabled false
shrinkResources false
multiDexEnabled true
}
release {
minifyEnabled true
shrinkResources true
multiDexEnabled false
}
}
lintOptions {
warning 'InvalidPackage', 'GradleCompatible'
}
dexOptions {
preDexLibraries true
incremental true
jumboMode = true
javaMaxHeapSize "4g"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
得到这个工作。我已将multiDexEnabled true模块app的build.gradle. 但我正在其他模块中运行单元测试。事实证明我multiDexEnabled true还需要添加该模块。
android {
buildTypes {
debug {
multiDexEnabled true
}
}}
Run Code Online (Sandbox Code Playgroud)