android – 运行单元测试用例时的Multidex限制命中

我有一个应用程序,我有本地单元测试(测试文件夹)和仪表单元测试用例( 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.我想当运行检测测试用例时,它们以调试模式运行.那为什么会发生这种异常呢?

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


  }
}

}

解决方法

得到这个工作.我在应用程序模块的build.gradle中放了multiDexEnabled.但我在其他模块中运行单元测试.事实证明我还需要在该模块中添加multiDexEnabled true.
android {
  buildTypes {
    debug {
      multiDexEnabled true
    }
  }}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...