/android/app/build/intermediates/res/merged/release/drawable-hdpi/node_modules_reactnative_libraries_customcomponents_navigationexperimental_assets_backicon.png
android/app/build/intermediates/res/merged/release/drawable-hdpi-v4/node_modules_reactnative_libraries_customcomponents_navigationexperimental_assets_backicon.png: error: Duplicate file.
通过 GitHub issues里提到的解决方案
I found the root cause is that old version's packager collect resources (image etc.) and put under $(rn_project)\android\app\src\main\res, while newer version put them under $(rn_project)\android\app\build\intermediates\res\merged$(buildType). It brings duplication which leads to failure of task 'processReleaseResources'. And it also explains why new created project works well. When you have an old RN project upgrading to newer version, just delete directories like 'drawable-xxxx' (ATTN:no 'v?' postfix) under $(rn_project)\android\app\src\main\res and wolrd will be nice.
简单翻译一下就是,旧版本的打包方式是把资源放在了$(rn_project)\ android \ app \ src \ main \ res下,新版的打包方式是在编译的$(rn_project)\android\app\build\intermediates\res\merged$(buildType)下,所以会造成重复文件的问题,导致导致任务“processReleaseResources”失败
解决方法是把$(rn_project)\android\app\src\main\res文件夹下的带有drawable-xxxx的文件夹删掉就可以了
function getAndroidAssetSuffix(scale) {
switch (scale) {
case 0.75: return 'ldpi-v4';
case 1: return 'mdpi-v4';
case 1.5: return 'hdpi-v4';
case 2: return 'xhdpi-v4';
case 3: return 'xxhdpi-v4';
case 4: return 'xxxhdpi-v4';
}
}
@AvatarQing 把这个统一集成到了react.gradle 里面完美的解决掉了drawable-xxxx重复文件的问题
在react.gradle里的def currentBundleTask = tasks.create方法里面最后面添加:
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()
}
共勉
GitHub issues