1.項(xiàng)目中使用了babel-preset-react-app庫直接使用以下命令打包js資源
react-native bundle --platform android --dev false --entry-file src/index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
會(huì)報(bào):
Using babel-preset-react-app
requires that you specify NODE_ENV
or BABEL_ENV
異常
處理方法:
1.在項(xiàng)目根目錄創(chuàng)建.babelrc文件笋鄙,代碼如下:
{
"presets": ["module:metro-react-native-babel-preset"],
"env": {
"production": {
}
},
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
2.導(dǎo)入cross-env,不導(dǎo)入此庫浊伙,BABEL_ENV命令無法找到
npm i cross-env
通過以下命令打包:
cross-env BABEL_ENV=production react-native bundle --platform android --dev false --entry-file src/index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
BABEL_ENV有三種方式選擇:1.test, 2:development, 3:production
2.assembleRelease打包失敗Duplicate file
舊版本的打包方式是把資源放在了\ android \ app \ src \ main \ res下,新版的打包方式是在編譯的\android\app\build\intermediates\res\merged$(buildType)下,所以會(huì)造成重復(fù)文件的問題,導(dǎo)致導(dǎo)致任務(wù)“processReleaseResources”失敗
解決方法是把\android\app\src\main\res文件夾下的帶有drawable-xxxx的文件夾刪掉就可以了