Kaspresso icon indicating copy to clipboard operation
Kaspresso copied to clipboard

Resolve Error while merging dex archives "DexArchiveMergerException"

Open ultraon opened this issue 3 years ago • 6 comments

When I run instrumentation tests from terminal using ./gradlew clean app:connectedDebugAndroidTest using Kaspresso dependency, Gradle shows me an error:

> A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
   > There was a failure while executing work items
      > A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
         > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
           Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
           Type android.support.v4.app.INotificationSideChannel is defined multiple times: /Users/myuser/.gradle/caches/transforms-2/files-2.1/5e95fa91c034537d18b6430f6cfedd80/core-1.5.0-runtime/classes.dex, /Users/myuser/.gradle/caches/transforms-2/files-2.1/beb8b83d149d5121f4df541f456092a8/core-1.5.0-runtime/classes.dex

ultraon avatar Jun 07 '21 18:06 ultraon

To fix the issue you need to exclude androidx.core:core transitive dependency from androidTest "com.kaspersky.android-components:kaspresso:${Versions.kaspresso}":

dependencies {
  // ...
  androidTestImplementation("com.kaspersky.android-components:kaspresso:${Versions.kaspresso}") {
    exclude group: "androidx.core", module: "core"
  }
}

ultraon avatar Jun 07 '21 18:06 ultraon

@ultraon thank you for your research! @RuslanMingaliev please keep in mind

matzuk avatar Jun 11 '21 05:06 matzuk

@ultraon which Gradle version do you use in your project?

RuslanMingaliev avatar Jun 15 '21 13:06 RuslanMingaliev

Gradle - 6.7.1, Android Gradle Plugin - 4.2.1

ultraon avatar Jun 15 '21 14:06 ultraon

It is worth to mention, without the fix https://github.com/KasperskyLab/Kaspresso/issues/258#issuecomment-856173894 it is built successfully, but need to run the same cmd 2nd time ./gradlew app:connectedDebugAndroidTest (but without clean).

ultraon avatar Jun 15 '21 14:06 ultraon

Faced a similar problem when upgrading from 1.3 to 1.4 Gradle - 6.5 \ Android Gradle Plugin - 4.1.3

~~any idea how to fix this problem? (excluding fix from #258 (comment) )~~ UPD: helped change compileSdkVersion 30 to 31

el-qq avatar Nov 29 '21 17:11 el-qq

Hi, @ultraon! I've tried to reproduce your issue on sample project with Kaspresso 1.4.2 and explicit androidx.core dependency, but unfortunately with no luck.

Kaspresso 1.4.2 uses androidx.core 1.9.0 which requires compileSdk 33. Please:

  1. Update your Kaspresso version to 1.4.2
  2. Bump your compileSdk to 33
  3. Remove explicit dependency on androidx.core if you don't really need specific version
  4. Use exclude expression otherwise Also I'd suggest you to use newer gradle and AGP.

Unfortunately, none of these steps could be done on Kaspresso side so we're leaning to closing this issue. Please tell us if you need any further help

Nikitae57 avatar Oct 31 '22 09:10 Nikitae57

Please, re-open if you went through steps above and still experience this issue

Nikitae57 avatar Oct 31 '22 14:10 Nikitae57