0

I'm already search several information related to this issue. When I use com.midtrans:uikit:1.21.2 and :react-native-camera then run the build script, this error occurred.

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

This error is refers to this line on rootProject/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml enter image description here

Then i found that if there are multiple key with the same value.

  1. react-native-camera resources on android/src/main/res/value/attrs.xml with key <attr format="string" name="aspectRatio"/>
  2. com.midtrans:uikit resources on uikit/src/main/res/value/attrs.xml with key <attr format="float" name="aspectRatio"/>

I need help to fix this error, or any information to fix/avoid this situation. There are some thread that I checked.

  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

Any help would be thanks.

Bukhari
  • 492
  • 3
  • 15
  • Try this command rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache.. It works for me. Before running it, shut the Android Studio, if open. – Aaditya Paliwal Jan 29 '19 at 04:23
  • @AadityaPaliwal I tried it, but `no matches found: /var/folders/jr/k4qv5jt10nb462n4f_vc76p80000gn/T//react-*` occured – Bukhari Jan 29 '19 at 04:45

1 Answers1

1

Few solution you might interested to:

  1. Fork the react-native-camera in GitHub to yours and modify the styles.xml and attrs.xml and add it to your react native project.

  2. Use the other's forked project from com.midtrans in here. Veritrans has clearly stated that they won't support react-native project and might not merge this pull request.

I will recommend the solution no 1. I have forked and modify the resource value and some modification on others to follow my requirement needs. Feel free to take a look: here