运行 Multidexed Espresso .APK

Roc*_*nat 4 android android-espresso android-multidex

使用 运行 Espresso 测试时./gradlew connectedDebugAndroidTest,我们遇到了这个问题:

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: 方法 ID 不在 [0, 0xffff]: 65536

由于我们在主应用程序中使用 Multidex 并且只是在检测的测试中添加 Espresso 依赖项,我们不明白为什么它不起作用:·(此外,如果我们通过 IntelliJ 而不是 Gradle 运行测试,它有效:·|

顺便说一下,我们需要通过 Gradle 运行它们以在 CI 工具上自动化它们。

更多信息?在 Google 的问题跟踪器上有一个相关问题的链接:https ://issuetracker.google.com/issues/37017515 :sad:

iva*_*arz 6

该任务connectedDebugAndroidTest将尝试为项目中的每个模块构建测试 apk,因此如果您的项目有多个模块,则需要在每个模块中启用 multidex。这通常是完成设置

android.defaultConfig.multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)

build.gradle每个模块中。

对于没有任何测试的模块,如果您只是不尝试在这些模块中执行任务,则可以跳过所有这些。例如,如果只有app模块有仪器测试,您可以app:connectedDebugAndroidTest改为执行以避免可能的 multidex 错误。这实际上是默认情况下由 Android Studio 创建的运行配置所做的,这可能也是当您从 IDE 启动它们时您的测试运行良好的原因。