4

When running Espresso tests with ./gradlew connectedDebugAndroidTest, we're having this issue:

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

As we're using Multidex at the main app and just adding the Espresso dependencies on the instrumented test one, we don't get why it doesn't work :·( In addition, if we run the tests via IntelliJ instead of Gradle, it works :·|

By the way, we need to run them via Gradle to automate them on the CI tool.

More information? There's a link to a related issue on Google's issue tracker: https://issuetracker.google.com/issues/37017515 :sad:

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
  • Are your tests in a different module? – Eduard B. May 03 '17 at 17:23
  • Nope, they are placed in the common `app` module. You know: `/app/src/androidTest`. By the way, the app is composed of more modules. Did you experiment issues with this configuration? Thanks @EduardB. :·) – Roc Boronat May 04 '17 at 09:44
  • The issue that we had was with the tests that were in the other modules, as we didn't find a way to enable multidex for the respective modules for the test configuration. Our solution was to put the tests in the main app module. That's why I asked. Sorry that I can't really help more than this. – Eduard B. May 04 '17 at 09:50
  • 1
    Oh, sharing your experience is really appreciated! Thanks for it! – Roc Boronat May 04 '17 at 13:49

1 Answers1

6

The task connectedDebugAndroidTest will try to build test apks for every module in the project, so if you project has multiple modules, you need to enable multidex in every one of them. This is usually done setting

android.defaultConfig.multiDexEnabled true

in build.gradle for each module.

You could skip all of this for modules that don't have any tests if you just don't try to execute the task in those. e.g, if only the app module has instrumentation tests, you could execute app:connectedDebugAndroidTest instead to avoid the possible multidex errors. This is actually what the run configuration created by Android Studio does by default, and probably the reason why your tests are running just fine when you launch them form the IDE.

ivagarz
  • 2,434
  • 22
  • 22
  • 1
    Thank you @ivangarz! Just added `multiDexEnabled true` at all the modules, and it worked like a charm! Thanks a lot, you saved my day. And my week. And my month! – Roc Boronat May 11 '17 at 09:41
  • Saved hours of debugging, thank you. They really should include this in the docs.... – mvbrenes Oct 21 '19 at 03:05