Maximum range hits during unit test

I have an application where I have local tests ( test folder ) and unit test hardware ( androidTest folder ). Right now, if I click on the androidTest folder and click on “ Run all tests ”, it raises the following exception.

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 

This exception is clearly related to reaching the multidex limit. But I turned on multi-dex to build debugging. I think that when test tests run, they run in debug mode. Then why does this exception arise?

I attach the build.gradle file

 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" } } } } 
+8
android unit-testing
source share
1 answer

To make it work. I put multiDexEnabled true in the app module build.gradle . But I did unit tests in some other module. Turns out I needed to add multiDexEnabled true to this module.

 android { buildTypes { debug { multiDexEnabled true } }} 
0
source share

All Articles