android - 在没有开发服务器的设备上构建和安装未签名的 apk?

标签 android apk react-native

由于我是 react-native 的新手,所以如果步骤有任何问题,请告诉我。

我已经按照文档使用命令构建了一个 react native android 应用程序

react-native android

在设备上运行时使用了以下命令

react-native run-android

这给了我 projectfolder/android/app/build/outputs/apk

中 2 个 apk 文件的输出

enter image description here

现在,当我在安装后安装此 apk 时,它会要求开发服务器连接以 bundle JS。但我的要求是用户不必为开发服务器而苦苦挣扎,他只需要安装 apk 就可以了。

经历了一些stackoverflow Questions但对构建不需要开发服务器的未签名 apk 没有帮助。

你们能帮我找到如何在 react native 中构建和未签名的 apk 的方法吗?

最佳答案

您需要为调试构建手动创建 bundle 。

bundle 调试构建:

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

#React-Native 0.49.0+
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

#React-Native 0-0.49.0
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug

然后在打包后构建APK:

$ cd android
#Create debug build:
$ ./gradlew assembleDebug
#Create release build:
$ ./gradlew assembleRelease #Generated `apk` will be located at `android/app/build/outputs/apk`

附:另一种方法可能是修改 gradle 脚本。

关于android - 在没有开发服务器的设备上构建和安装未签名的 apk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35283959/

相关文章:

android - 是否可以在Android下运行一个MIDP应用程序

Android:对话框的宽度应该是多少?

android - 如何在以前的版本上测试 apk

android - AOSP - 在没有用户确认的情况下在后台安装包

android - 在 Android Studio 中单击运行时如何部署签名的 APK?

ios - React Native 启动/启动画面最佳实践?

android - 如何在执行 doInBackground() 时在 android 中显示进度微调器

android - ZBar 库构建失败,Android NDK(预期标识符或 '(' 之前的 '.')

twitter-bootstrap - React-Bootstrap下拉按钮pullRight/Left

javascript - 无法在 GraphQL 突变中传递数组 - React Native