问题解决 react-native android打包报错:Error: Duplicate resources

转载自: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

å¨è¿éæå¥å¾çæè¿°

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值