react native 打Android apk报错 Dupl
2019-03-24 本文已影响0人
萤火虫叔叔
react-native
版本0.57.8
打包遇到一个莫名其妙的错误:Duplicate resources
。
一、解决办法
修改react-native
的react.gradle
文件。在路径your project/node_modules\react-native
路径下,找到doFirs
t,在其后添加doLast
以及大括号中的内容,如下所示
// Create dirs if they are not there (e.g. the "clean" task just ran)
doFirst {
jsBundleDir.deleteDir()
jsBundleDir.mkdirs()
resourcesDir.deleteDir()
resourcesDir.mkdirs()
}
// to resolve Error: Duplicate resources
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()
}
二、如果还不行
可能是项目缓存导致的,所以,用Android studio clean project
之后,再重复上述办法。