gpt4 book ai didi

android - 运行单元测试用例时达到 Multidex 限制

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:59:43 25 4
gpt4 key购买 nike

我有一个应用程序,其中有本地单元测试(测试文件夹)和仪器单元测试用例(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

这个异常显然是因为达到 multidex 限制。但是我已经为调试构建启用了 multi-dex。我想当仪器测试用例运行时,它们是在 Debug模式下运行的。那为什么会出现这个异常呢?

我正在附加 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"
}


}
}

}

最佳答案

让这个工作。我在 app 模块的 build.gradle 中设置了 multiDexEnabled true。但是我在其他一些模块中运行单元测试。事实证明,我还需要在该模块中添加 multiDexEnabled true

android {
buildTypes {
debug {
multiDexEnabled true
}
}}

关于android - 运行单元测试用例时达到 Multidex 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37001283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com