转载自:https://blog.csdn.net/qq_33466661/article/details/106901621
问题
react-native项目,在打Android包时,报错:Error: Duplicate resources
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [raw/node_modules_reactnativevectoricons_glyphmaps_feather] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_feather.json [raw/node_modules_reactnativevectoricons_glyphmaps_feather] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_feather.json: Error: Duplicate resources
[raw/js_saga_msg] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/js_saga_msg.json [raw/js_saga_msg] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/js_saga_msg.json: Error: Duplicate resources
[raw/app] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/app.json [raw/app] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/app.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome.json [raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_fontawesome.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_zocial] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_zocial.json [raw/node_modules_reactnativevectoricons_glyphmaps_zocial] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_zocial.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_entypo] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_entypo.json [raw/node_modules_reactnativevectoricons_glyphmaps_entypo] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_entypo.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_antdesign] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_antdesign.json [raw/node_modules_reactnativevectoricons_glyphmaps_antdesign] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_antdesign.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_foundation] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_foundation.json [raw/node_modules_reactnativevectoricons_glyphmaps_foundation] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_foundation.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_evilicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_evilicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_evilicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_evilicons.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_octicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_octicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_octicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_octicons.json: Error: Duplicate resources
[raw/node_modules_reactnativecodepush_package] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativecodepush_package.json [raw/node_modules_reactnativecodepush_package] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativecodepush_package.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_simplelineicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_simplelineicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_simplelineicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_simplelineicons.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_materialcommunityicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_materialcommunityicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_materialcommunityicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_materialcommunityicons.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_materialicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_materialicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_materialicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_materialicons.json: Error: Duplicate resources
[raw/node_modules_reactnativevectoricons_glyphmaps_ionicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/src/main/res/raw/node_modules_reactnativevectoricons_glyphmaps_ionicons.json [raw/node_modules_reactnativevectoricons_glyphmaps_ionicons] /Users/momo/Documents/Demo/react-native-apps/app2.0/android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_ionicons.json: Error: Duplicate resources
解决方法
以下三种,我是同时使用才能重新打包成功的。在别的博客里也看到用其中一种就成功解决了的。
方法一
将报错的重复资源删掉
方法二
修改node_modules\react-native\react.gradle,在doFirst后面加上doLast
参考:https://github.com/facebook/react-native/issues/22234
doFirst { ... }
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 打开项目,然后选择build–>Clean Project