Android - Task :app:mergeDexRelease FAILED
Asked Answered
C

2

6

please consider that I'm not very familiar with Android development.

Trying to generate the Android signed bundle for my React Native app, I've stumbled upon the following error:

Task :app:mergeDexRelease FAILED
D8: Program type already present: com.horcrux.svg.Brush$BrushType
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.
Program type already present: com.horcrux.svg.Brush$BrushType

...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > 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.
     Program type already present: com.horcrux.svg.Brush$BrushType
  • I'm aware that BrushType is a class from react-native-svg
  • I've ran gradlew app:dependencies and found no module depending on Brush or anything related to com.horcrux.svg or react-native-svg
  • Already tried cleaning project, deleting .iml files, invalidating Android Studio caches, rebuilding, reinstalling node_modules and so on
  • Tried messing with build.gradle and gradle.properties with no luck
  • I've read through this android guide on duplicate classes also with no luck

I understand that there are 2 or more dependencies utilizing com.horcrux.svg.Brush$BrushType but I can't find them. I imagine that once I find them, I could do

implementation(:my-library) {
  exclude ...
}

Correct?

gradle.properties

android.useAndroidX=true
android.enableJetifier=true

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2560m

android/app/build.gradle

dependencies {
    implementation project(':react-native-appearance')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':watermelondb')
    implementation project(':react-native-calendar-events')

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

Thanks in advance.

EDIT:

Solved by adding:

    implementation(project(':react-native-jitsi-meet')) {
      ...
      exclude group: 'com.facebook.react',module:'react-native-svg'
      ...
    }

In my case it was react-native-jitsi-meet that was causing the conflicts, I had to find it via trial and error.

Capella answered 6/4, 2020 at 19:32 Comment(4)
any solutions found for this issue ?Condorcet
Any solution found?Dejecta
@Dejecta I updated the post with the solution to my caseCapella
its working finallyMireielle
B
3
defaultConfig {
    ..............
    multiDexEnabled true
}

dependencies {
    ..............
    implementation 'androidx.multidex:multidex:2.0.1'
}

public class MyApplication extends MultiDexApplication {
    ..............
}
Befit answered 3/8, 2020 at 10:30 Comment(0)
S
2

Resolved: I have two packages @react-native-masked-view/masked-view (from previous developer) and @react-native-community/masked-view. Just remove @react-native-masked-view/masked-view package and try build.

https://github.com/react-native-masked-view/masked-view/issues/100#issuecomment-841634389 Thanks to: Navipro70

Stilla answered 26/9, 2021 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.