在不同依赖项之间的values.xml上的React Native构建错误重复键

时间:2019-01-29 04:09:24

标签: android reactjs react-native

我已经搜索了与此问题相关的一些信息。当我使用com.midtrans:uikit:1.21.2:react-native-camera然后运行构建脚本时,发生此错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
  Output:  /rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:492: error: duplicate value for resource 'attr/aspectRatio' with config ''.
  /rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:492: error: resource previously defined here.

  Command: /userRoot/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/26099ef957fce779fbc384e01d71f8d6/aapt2-3.2.1-4818971-osx/aapt2 compile --legacy \
          -o \
          /rootProject/android/app/build/intermediates/res/merged/debug \
          /rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
  Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0
  Output:  /userRoot/.gradle/caches/transforms-1/files-1.1/cardview-v7-26.1.0.aar/f44a4b5427df6e671eadd76860228e04/res/values/values.xml:7:5-685: AAPT: error: duplicate value for resource 'attr/aspectRatio' with config ''.

  /userRoot/.gradle/caches/transforms-1/files-1.1/cardview-v7-26.1.0.aar/f44a4b5427df6e671eadd76860228e04/res/values/values.xml:7:5-685: AAPT: error: resource previously defined here.

  Command: /userRoot/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/26099ef957fce779fbc384e01d71f8d6/aapt2-3.2.1-4818971-osx/aapt2 compile --legacy \
          -o \
          /rootProject/android/app/build/intermediates/res/merged/debug \
          /rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
  Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0

此错误是指rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml上的这一行 enter image description here

然后我发现如果有多个键具有相同的值。

  1. react-native-camera上的{li} android/src/main/res/value/attrs.xml resources,键为<attr format="string" name="aspectRatio"/>
  2. com.midtrans:uikit上的{li} uikit/src/main/res/value/attrs.xml resources,键为<attr format="float" name="aspectRatio"/>

我需要帮助来纠正此错误,或者需要任何信息来纠正/避免这种情况。 我检查了一些线程。

  1. React Native : Error: Duplicate resources - Android
  2. Unable to build android (because of duplicate dependecies ?)
  3. React Native Error: Duplicate resources, assets coming in some screens and not coming in others in android release APK

任何帮助都是谢谢。

1 个答案:

答案 0 :(得分:1)

您可能不感兴趣的几种解决方案:

  1. 将GitHub中的react-native-camera分支给您,并修改styles.xml和attrs.xml并将其添加到您的react native项目中。

  2. 使用here中com.midtrans的另一个分叉的项目。 Veritrans明确表示他们将不支持react-native项目,并且可能不会合并此请求请求。

我将建议解决方案1。我已分叉并修改了资源值,并对其他值进行了一些修改以符合我的需求。随时查看:here