今天使用android studio給react-native項(xiàng)目打正式包,發(fā)現(xiàn)居然報(bào)Duplicate resources的錯(cuò)
截圖_20190716171935.png
誒吓肋,原來運(yùn)行app很正常啊,查資料日常填坑ヽ(`Д′)?︵ ┻━┻ ┻━┻
后再stackoverflow上果然找到相同的問題(React Native : Error: Duplicate resources - Android - Stack Overflow)
截圖_20190716172837.png
很好,照做
修改的
文件。在路徑y(tǒng)our project/node_modules\react-native路徑下着绊,找到
,在其后添加
以及大括號(hào)中的內(nèi)容
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熟尉,重新打包归露,發(fā)現(xiàn)有效,但還有報(bào)錯(cuò)
截圖_20190716172319.png
drawable的問題已經(jīng)解決斤儿,但由于使用到了raw文件夾下的資源剧包,raw文件夾也存在資源重復(fù)恐锦。那好,照葫蘆畫瓢疆液,繼續(xù)修改
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()
}