KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.78k stars 150 forks source link

Resolve Error while merging dex archives "DexArchiveMergerException" #258

Closed ultraon closed 1 year ago

ultraon commented 3 years ago

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 commented 3 years ago

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"
  }
}
matzuk commented 3 years ago

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

RuslanMingaliev commented 3 years ago

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

ultraon commented 3 years ago

Gradle - 6.7.1, Android Gradle Plugin - 4.2.1

ultraon commented 3 years ago

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).

el-qq commented 2 years ago

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

Nikitae57 commented 1 year ago

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 commented 1 year ago

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