今天使用android studio给react-native项目打正式包,发现居然报Duplicate resources的错
截图_20190716171935.png
诶,原来运行app很正常啊,查资料日常填坑ヽ(`Д´)ノ︵ ┻━┻ ┻━┻
后再stackoverflow上果然找到相同的问题(React Native : Error: Duplicate resources - Android - Stack Overflow)
截图_20190716172837.png
很好,照做
修改的
文件。在路径your project/node_modules\react-native路径下,找到
,在其后添加
以及大括号中的内容
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/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()
}
然后用as clean project,重新打包,发现有效,但还有报错
截图_20190716172319.png
drawable的问题已经解决,但由于使用到了raw文件夹下的资源,raw文件夹也存在资源重复。那好,照葫芦画瓢,继续修改
doLast {
...
File oldRawDir = file("$buildDir/generated/res/react/release/raw");
if (oldRawDir.exists()) {
File rawDir = file("$buildDir/../src/main/res/raw");
ant.move(file: oldRawDir, tofile: rawDir);
}
...
}
clean project,重新打包,完美解决ヾ(゚∀゚ゞ)
完整代码
doLast {
def moveFunc = { resSuffix ->
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
File oldRawDir = file("$buildDir/generated/res/react/release/raw");
if (oldRawDir.exists()) {
File rawDir = file("$buildDir/../src/main/res/raw");
ant.move(file: oldRawDir, tofile: rawDir);
}
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()
}