Skip to content

Commit eb534bc

Browse files
Dbroquafacebook-github-bot
authored andcommitted
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](#22234) and pull request [24518](#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: #24778 Differential Revision: D15277766 Pulled By: cpojer fbshipit-source-id: 0ccd76d2aa2e13f7c8bfac07d4ef23b74945807a
1 parent 962437f commit eb534bc

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

react.gradle

+9-8
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,19 @@ afterEvaluate {
6060
// Address issue #22234 by moving generated resources into build dir so they are in one spot, not duplicated
6161
doLast {
6262
def moveFunc = { resSuffix ->
63-
File originalDir = file("$buildDir/generated/res/react/${flavorPathSegment}release/drawable-${resSuffix}")
63+
File originalDir = file("$buildDir/generated/res/react/${flavorPathSegment}release/${resSuffix}")
6464
if (originalDir.exists()) {
65-
File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}")
65+
File destDir = file("$buildDir/../src/main/res/${resSuffix}")
6666
ant.move(file: originalDir, tofile: destDir);
6767
}
6868
}
69-
moveFunc.curry("ldpi").call()
70-
moveFunc.curry("mdpi").call()
71-
moveFunc.curry("hdpi").call()
72-
moveFunc.curry("xhdpi").call()
73-
moveFunc.curry("xxhdpi").call()
74-
moveFunc.curry("xxxhdpi").call()
69+
moveFunc.curry("drawable-ldpi").call()
70+
moveFunc.curry("drawable-mdpi").call()
71+
moveFunc.curry("drawable-hdpi").call()
72+
moveFunc.curry("drawable-xhdpi").call()
73+
moveFunc.curry("drawable-xxhdpi").call()
74+
moveFunc.curry("drawable-xxxhdpi").call()
75+
moveFunc.curry("raw").call()
7576
}
7677

7778
// Set up inputs and outputs so gradle can cache the result

0 commit comments

Comments
 (0)