【问题标题】:React native release version build fails with D8: Program type already present: com.reactnativecommunity.webview.BuildConfigReact 本机发布版本构建失败并出现 D8:程序类型已存在:com.reactnativecommunity.webview.BuildConfig
【发布时间】:2021-01-31 13:17:20
【问题描述】:

在我从事的一个 React 本机项目中,我想使用 react-native-webview 在视图上显示一些 HTML 内容。

添加包react-native-webview 后,gradlew buildRelease 开始失败并显示以下错误消息;

执行的命令是.\gradlew bundleRelease

输出是

> Task :app:mergeDexRelease FAILED
D8: Program type already present: com.reactnativecommunity.webview.BuildConfig
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Program type already present: com.reactnativecommunity.webview.BuildConfig
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
        at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
        at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118)
        at 
.....

FAILURE: Build failed with an exception.

【问题讨论】:

    标签: android react-native react-native-webview


    【解决方案1】:

    我注意到react-native-webview 包也包含在com.facebook.react 包中。排除来自这个包的包可以解决问题。

    您需要在app/build.gradle文件中添加以下内容

    exclude group: 'com.facebook.react',module:'react-native-webview'
    

    【讨论】:

      【解决方案2】:

      在 app/build.gradle 中编辑文件:

      configurations.all {
          resolutionStrategy.eachDependency { DependencyResolveDetails details ->
              def requested = details.requested
              if (requested.group == 'com.android.support' && requested.name != 'multidex') {
                  details.useVersion "${rootProject.ext.supportLibVersion}"
              }
          }
      }
      

      【讨论】:

      • 很遗憾,没有解决问题。configurations.all 没有条目,我添加到文件中但没有解决问题。
      猜你喜欢
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 2019-04-05
      • 2019-06-30
      相关资源
      最近更新 更多