Error: Duplicate resources

本文详细介绍了如何解决在React Native项目中遇到的[drawable-xhdpi-v4]png:Error:Duplicateresources错误。通过修改react.gradle文件,在doFirst和doLast中添加特定代码,实现清理和移动资源目录,有效避免资源重复问题。
[drawable-xhdpi-v4]png: Error: Duplicate resources

解决办法:
https://stackoverflow.com/questions/53239705/react-native-error-duplicate-resources-android

找到node_modules/react-native/react.gradle,
在doFirst后面加上如下代码,如下:

			doFirst {
                jsBundleDir.deleteDir()
                jsBundleDir.mkdirs()
                resourcesDir.deleteDir()
                resourcesDir.mkdirs()
            }
            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()
            }
Incubating] Problems report is available at: file:///C:/Users/V76246960/AndroidStudioProjects/UsbNetwork/build/reports/problems/problems-report.html FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeReleaseResources'. > [string/proxy_exclusionlist_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_exclusionlist_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_hostname_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_hostname_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_port_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_port_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_url_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_url_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/sec_eth_ipaddr_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/sec_eth_ipaddr_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:packageReleaseResources'. > [string/proxy_exclusionlist_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_exclusionlist_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_hostname_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_hostname_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_port_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_port_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/proxy_url_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/proxy_url_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources [string/sec_eth_ipaddr_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\strings.xml [string/sec_eth_ipaddr_hint] C:\Users\V76246960\AndroidStudioProjects\UsbNetwork\app\src\main\res\values\styles.xml: Error: Duplicate resources * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. ============================================================================== Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. BUILD FAILED in 2s 30 actionable tasks: 5 executed, 25 up-to-date.
最新发布
11-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值