安卓打包APK问题
-
文档写得非常模糊
taro build --type rn
得到.rn_temp没问题
node ./node_modules/react-native/local-cli/cli.js bundle --entry-file ./rn_temp/index.js --bundle-output ./bundle/index.bundle --assets-dest ./${BUNDLE_DIR_NAME} --dev false
也能得到index.bundle和index.bundle.meta两个文件
然后就没办法往下走了
在react-native-shell
的壳子里,按照正常的RN打包程序,应该是cd ./android ./gradlew aR
但是RN官方执行脚本这个时候会去尝试打包jsBundle,会报错
进入./node_modules/react-native/react.gradle
禁用// runBefore("process${targetName}Resources", currentBundleTask)
可以跳过jsBundle和静态资源的打包
正常生成apk
但是这个apk安装运行会闪退尝试:
将上面生成的index.bundle和index.bundle.meta两个文件拷贝到壳子的/android/app/assets/路径下
修改MainApplication.java中的@Override protected String getJSMainModuleName() { return "index"; }
重新打包,依然不行,apk运行会闪退
别再让我看https://nervjs.github.io/taro/docs/1.3.25/react-native.html#%E6%9E%84%E5%BB%BA-app了
文档写得太模糊不清了,只能来这里求助了
-
问题暂时解决
taro build --type rn
得到rn_temp文件夹,copy到壳子的根目录下,
修改壳子的android/app/build.gradleproject.ext.react = [ entryFile: "rn_temp/index.js", ]
node ./node_modules/react-native/local-cli/cli.js bundle --entry-file ./rn_temp/index.js --bundle-output ./bundle/index.android.bundle --assets-dest ./${BUNDLE_DIR_NAME} --dev false
得到index.android.bundle和index.bundle.meta两个文件copy到android/app/src/main/assets/
没有就创建一个
修改android/app/src/main/java/MainApplication.java@Override protected String getJSMainModuleName() { return "index"; }
然后正常运行RN的打包命令
cd ./android ./gradlew aR
-
@幻之苍岚 同感,我也被这个问题坑了,打包成 apk 时不会包含 index.android.bundle 等文件。导致打开应用时闪退。
你的方法可以使用。我找到了另外的方法。
参考文档:
https://github.com/microsoft/react-native-code-push/issues/1427
https://github.com/facebook/react-native/issues/211321.将编译后好
rn_temp
目录copy到 taro-native-shell 根目录下2.修改
taro-native-shell\android\app\build.gradle
文件,设置jsBundleDirDebug
与jsBundleDirRelease
(关键步骤,其他地方都不用改)project.ext.react = [ entryFile: "rn_temp/index.js", jsBundleDirDebug: "$buildDir/intermediates/merged_assets/debug/mergeDebugAssets/out", jsBundleDirRelease: "$buildDir/intermediates/merged_assets/release/mergeReleaseAssets/out" ]
- 在
taro-native-shell/android
下运行命令打包(一样的步骤)
//windows 下 //打包并运行 react-native run-android --variant=release //或单纯打包: gradlew assembleRelease //最终APK包在该目录下:taro-native-shell\android\app\build\outputs\apk\release
- 其他
打包、签名参考
- 在
-
第3点有笔误
3.打包、运行
3.1 打包:在taro-native-shell/android
目录下运行
最终APK包在该目录下:taro-native-shell\android\app\build\outputs\apk\release//linux,mac ./gradlew assembleRelease //windows gradlew assembleRelease
3.2 打包并运行
在taro-native-shell
根目录下react-native run-android --variant=release
-
此回复已被删除!
-
@mdx86 所以归根结底是Taro官方虽然用了0.55.4的RN,但是擅自升级Gradle到3.3.0的锅咯……
-
@幻之苍岚 应该是的,和Gradle 与 Gradle plugin 版本有关,这两个东西我目前还没捋清楚,