如何在 React Native 中生成无需开发服务器即可运行的 apk

How to generate an apk that works without dev server in react native

我正在使用 react-native (0.59) 开发一个 android 应用程序,我想在不同的设备上测试它。我的目标是创建一个 .apk 文件,只需传输文件即可安装,不需要开发服务器 运行ning、usb 电缆等。

我查看了关于该主题的先前问题的不同回复,但到目前为止没有任何效果。

此回复仍需要一个开发服务器才能 运行:

此回复生成的 apk 无法安装在设备上并出现错误 "app not installed":Build and Install unsigned apk on device without the development server?

我已经尝试了 react-native 文档中的发布方法(参考:https://facebook.github.io/react-native/docs/signed-apk-android), I generated the .aab file, then I use bundletools to convert it with apks, as explained here: 在这个答案中:

So far nobody has provided the solution to get the APK from an AAB.

This solution will generate a universal binary as an apk.

Add --mode=universal to your bundletool command (if you need a signed app, use the --ks parameters as required).

bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks --mode=universal Change the output file name from .apks to .zip

Unzip and explore

The file universal.apk is your app

This universal binary will likely be quite big but is a great solution for sending to the QA department or distributing the App anywhere other than the Google Play store.

但不幸的是,在我的情况下,当我打开 .zip 文件时,没有名为 universal.apk:

的文件

所有 .apk 的大小都非常小(大约 10mb,而 .aab 文件为 300)。

还有其他解决办法吗?

完成 https://facebook.github.io/react-native/docs/signed-apk-android 后,您只需 运行

// for build and run
react-native run-android --variant=release

并在

中获取 apk
<rn_project_dir>/android/app/build/outputs/apk/release/app-release.apk