From eb534bca58a89ae306010626a8bdae92c23b8784 Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 9 May 2019 06:23:22 -0700 Subject: [PATCH] Fix duplicate resource error in Android gradle build (#22234) (#24778) Summary: If `$buildDir/generated/res/react/${flavorPathSegment}release/raw` contains files during `gradle assembleRelease` script will fail with `Error: Duplicate resources` error. This patch is based on this issue [22234](https://github.com/facebook/react-native/issues/22234) and pull request [24518](https://github.com/facebook/react-native/pull/24518). [Android] [Fixed] - Fix duplicate resource error for raw folder in Android build [CC from Mike Hardy PR] Reports of success on the linked issue via use of the patch + patch-package for a couple months, I personally use it full time with all gradle builds (./gradlew clean assembleRelease or if you have a 'staging' flavor, e.g. ./gradlew clean assembleStagingRelease) Related reading, also cross-links with the linked issue here: https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android Pull Request resolved: https://github.com/facebook/react-native/pull/24778 Differential Revision: D15277766 Pulled By: cpojer fbshipit-source-id: 0ccd76d2aa2e13f7c8bfac07d4ef23b74945807a --- react.gradle | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/react.gradle b/react.gradle index 488ebd6242567d..07fd9e3f2541be 100644 --- a/react.gradle +++ b/react.gradle @@ -60,18 +60,19 @@ afterEvaluate { // Address issue #22234 by moving generated resources into build dir so they are in one spot, not duplicated doLast { def moveFunc = { resSuffix -> - File originalDir = file("$buildDir/generated/res/react/${flavorPathSegment}release/drawable-${resSuffix}") + File originalDir = file("$buildDir/generated/res/react/${flavorPathSegment}release/${resSuffix}") if (originalDir.exists()) { - File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}") + File destDir = file("$buildDir/../src/main/res/${resSuffix}") ant.move(file: originalDir, tofile: destDir); } } - moveFunc.curry("ldpi").call() - moveFunc.curry("mdpi").call() - moveFunc.curry("hdpi").call() - moveFunc.curry("xhdpi").call() - moveFunc.curry("xxhdpi").call() - moveFunc.curry("xxxhdpi").call() + moveFunc.curry("drawable-ldpi").call() + moveFunc.curry("drawable-mdpi").call() + moveFunc.curry("drawable-hdpi").call() + moveFunc.curry("drawable-xhdpi").call() + moveFunc.curry("drawable-xxhdpi").call() + moveFunc.curry("drawable-xxxhdpi").call() + moveFunc.curry("raw").call() } // Set up inputs and outputs so gradle can cache the result