question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to merge dex error when using Mockito as androidTestImplementation

See original GitHub issue

Android Studio: 3.0 Gradle plugin: 3.0.0 Mockito: 2.11.0

I encounter the following issue when trying to use Mockito in instrumented unit tests (connectedAndroidTest):

Error:Execution failed for task ‘:twinkle:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest’. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

I have the following test dependencies in build.gradle:

testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:3.5.1'
testImplementation 'org.mockito:mockito-core:2.11.0'

androidTestImplementation 'com.android.support:support-annotations:27.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'org.mockito:mockito-core:2.11.0'

androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

Has anyone else had this issue? I have also included the linkedin dexmaker for mockito to attempt to remedy the issue, to no avail. Any help on this would be greatly appreciated!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
marcosaliscommented, Feb 8, 2018

Just my two cents. In my case adding multiDexEnabled true worked, but I had to add it to all the modules which the application was made of, not only the application module.

0reactions
AhmadSadiq0commented, Jan 1, 2019

Paste this in app.gradle below defaultConfig{}.It worked for me

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to merge dex with androidTestImplementation
I get an unable to merge dex exception when i try to run my android test together with uiAutomation. androidTestImplementation ...
Read more >
NullPointerException on a project with mockito-android as ...
gradlew assembleAndroidTest` fails when `androidTestImplementation 'org.mockito:mockito-android:2.21.0'` is part of the app dependencies in build.gradle ...
Read more >
Build Failed with an Exception – Unable to merge dex
What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.
Read more >
How to use Mockito together with MockK in Android ... - Medium
tl;dr: If you want to use both Mockito and MockK in the same Android instrumentation test, use this configuration: androidTestImplementation ...
Read more >
Gradle tips and recipes - Android Developers
Target specific builds with dependency configurations ... You can use the sourceSets block in the module-level build.gradle file to change where Gradle ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found