Created
May 31, 2019 12:58
-
-
Save maiquealmeida/2f0df4a5ab79c9d4a25dc142633ac3c1 to your computer and use it in GitHub Desktop.
Fixing React-Native android release error: duplicate resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doLast { | |
def moveFunc = { resSuffix -> | |
File originalDir = file("${resourcesDir}/drawable-${resSuffix}") | |
if (originalDir.exists()) { | |
File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4") | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
try { | |
var curDir = __dirname | |
var rootDir = process.cwd() | |
var file = `${rootDir}/node_modules/react-native/react.gradle` | |
var dataFix = fs.readFileSync(`${curDir}/android-gradle-fix`, 'utf8') | |
var data = fs.readFileSync(file, 'utf8') | |
var doLast = "doLast \{" | |
if (data.indexOf(doLast) !== -1) { | |
throw "Already fixed." | |
} | |
var result = data.replace(/\/\/ Set up inputs and outputs so gradle can cache the result/g, dataFix); | |
fs.writeFileSync(file, result, 'utf8') | |
console.log('Android Gradle Fixed!') | |
} catch (error) { | |
console.error(error) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
"postinstall": "node ./fixAndroid/android-release-fix.js" | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment