由于我是 react-native 的新手,所以如果步骤有任何问题,请告诉我。
我已经按照文档使用命令构建了一个 react native android 应用程序
react-native android
在设备上运行时使用了以下命令
react-native run-android
这给了我 projectfolder/android/app/build/outputs/apk
中 2 个 apk 文件的输出现在,当我在安装后安装此 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/