日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

react native中一次错误排查 Error:Error: Duplicate resources

發(fā)布時(shí)間:2024/9/21 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 react native中一次错误排查 Error:Error: Duplicate resources 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

最近一直在使用react native中,遇到了很多的坑,同時(shí)也學(xué)習(xí)到了一些移動端的開發(fā)經(jīng)驗(yàn)。

今天在做一個(gè)打包的測試時(shí),遇到了一個(gè)問題,打包過程中報(bào)錯“Error:Error: Duplicate resources”,什么意思呢,就是打包資源有重復(fù),后來查看了一下,發(fā)現(xiàn)打包到android/app/src目錄下的靜態(tài)文件重名了。

重現(xiàn)步驟:

1:通過vscode打開項(xiàng)目,運(yùn)行打包命令

react-native ram-bundle --entry-file index.js --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res/

2:

cd android && ./gradlew assembleRelease

?

查看android/app/src/mian/res/drawable目錄下靜態(tài)資源圖片文件名重復(fù)

?

解決方案

1:打開node_modules/react-native/react.gradle文件,在doFirst塊下添加doLast塊

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() }

2:打開node_modules/react-native/local-cli/bundle/assetPathUtils.js文件,修改getAndroidAssetSuffix函數(shù)方法如下

function getAndroidAssetSuffix(scale: number): string {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';}throw new Error('no such scale'); }

3:刪除android/app/src/main/res/drawable-**目錄下面打包進(jìn)去的靜態(tài)資源文件(文件名會比較長)

4:如果采用android studio進(jìn)行打包,點(diǎn)擊build下clean project,清除打包緩存

5:重新執(zhí)行打包命令即可打包成功。

?

參考資料:

1:https://github.com/facebook/react-native/issues/22234

2:https://blog.csdn.net/wyw223/article/details/84311733

?

轉(zhuǎn)載于:https://www.cnblogs.com/sk-3/p/10720933.html

總結(jié)

以上是生活随笔為你收集整理的react native中一次错误排查 Error:Error: Duplicate resources的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。