Skip to content

Instantly share code, notes, and snippets.

@maiquealmeida
Created May 31, 2019 12:58
Show Gist options
  • Save maiquealmeida/2f0df4a5ab79c9d4a25dc142633ac3c1 to your computer and use it in GitHub Desktop.
Save maiquealmeida/2f0df4a5ab79c9d4a25dc142633ac3c1 to your computer and use it in GitHub Desktop.
Fixing React-Native android release error: duplicate resource
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
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)
}
...
"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