5

请考虑我对Android开发不是很熟悉。

尝试为我的 React Native 应用程序生成 Android 签名包时,我偶然发现了以下错误:

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
  • 我知道这BrushType是一个类react-native-svg
  • 我跑了gradlew app:dependencies,发现没有模块依赖于Brush或与com.horcrux.svg或相关的任何东西react-native-svg
  • 已经尝试过清理项目、删除.iml文件、使Android Studio缓存失效、重建、重新安装node_modules
  • 尝试弄乱build.gradlegradle.properties没有运气
  • 我已经阅读了这个关于重复类的 android 指南,也没有运气

我知道有 2 个或更多依赖项在使用com.horcrux.svg.Brush$BrushType,但我找不到它们。我想一旦我找到它们,我就可以做到

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

正确的?

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
    }
}

提前致谢。

编辑:

通过添加解决:

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

就我而言,react-native-jitsi-meet这是导致冲突的原因,我必须通过反复试验找到它。

4

2 回答 2

1
defaultConfig {
    ..............
    multiDexEnabled true
}

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

public class MyApplication extends MultiDexApplication {
    ..............
}
于 2020-08-03T10:30:29.943 回答
0

已解决:我有两个包@react-native-masked-view/masked-view(来自以前的开发人员)和@react-native-community/masked-view. 只需删除@react-native-masked-view/masked-view软件包并尝试构建。

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

于 2021-09-26T00:14:56.130 回答