diff --git a/react.gradle b/react.gradle index 11b3465e51bdd9..488ebd6242567d 100644 --- a/react.gradle +++ b/react.gradle @@ -48,6 +48,32 @@ afterEvaluate { resourcesDir.mkdirs() } + + // If there are flavors, remember the current flavor for use in the resource path we move from + def flavorPathSegment = "" + android.productFlavors.all { flavor -> + if (targetName.toLowerCase().contains(flavor.name)) { + flavorPathSegment = flavor.name + "/" + } + } + + // 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}") + if (originalDir.exists()) { + File destDir = file("$buildDir/../src/main/res/drawable-${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() + } + // Set up inputs and outputs so gradle can cache the result inputs.files fileTree(dir: reactRoot, excludes: inputExcludes) outputs.dir(jsBundleDir)