前提:已经在taro壳子中做了相关打包的配置,已经在taro壳子中做了相关打包的配置,已经在taro壳子中做了相关打包的配置

taro版本2.2.13
1、 把项目根目录下的rn_temp文件夹复制到壳子根目录(taro-native-shell)下,再把rn_temp文件夹下的index.js文件复制到壳子根目录(taro-native-shell)下

2、打开壳子根目录下的index.js文件,修改“import App from './app.js';”为“import App from './rn_temp/app.js';”,修改“ import {name as appName} from './app.json';”为“ import {name as appName} from './rn_temp/app.json';”,如下图

3、终端进入壳子根目录(taro-native-shell),执行命令
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
会在android/app/src/main/assets文件夹下生成index.android.bundle文件

4、修改MainApplication中的getJSMainModuleName方法的返回值为“index.android.bundle”

5、终端中cd进入到android目录下,执行命令
./gradlew assembleRelease -x bundleReleaseJsAndAssets
等运行完成

你就可以在taro-native-shell/android/app/build/outputs/apk/release中看到打包出来的apk包了
或者可以按照Android studio的方式进行打包也可以。

网友评论