因为我是react-native的新手,所以如果有任何错误的步骤让我知道。
我已经用文档中的命令构建了一个react原生android应用程序
React-原生android
在设备上运行时,使用了以下命令
React-原生运行-Android
它给我的项目文件夹/android/app/build/outputs/apk中的2个apk文件的输出
现在,当我使用安装这个apk后,它要求一个开发服务器连接捆绑js。但我的要求是,用户不必与开发服务器作斗争,只需安装apk,一切就完成了。
已经经历了一些堆栈溢出问题,但对于构建不需要开发服务器的无签名apk没有帮助。
你们能帮我找到如何在react Native中建立和未签名apk的方法吗?
您需要手动创建用于调试构建的包。
捆绑调试生成:
#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`
附注。另一种方法可能是修改梯度脚本。
请按照这些步骤操作。
绑定JS:
如果在项目根中有index.android.js,那么运行
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
如果在项目根中有index.js,那么运行
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
创建调试APK:
cd android/
./gradlew assembleDebug
那么你可以在这里找到你的apk:
cd app/build/outputs/apk/
在根项目目录中
确保您已经有了android/app/src/main/assets/目录,如果没有创建目录,则创建新文件并另存为index.android.bundle
,然后将您的文件像这样放入android/app/src/main/assets/index.android.bundle中
然后运行这个
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/
cd android && ./gradlew assembleDebug
然后您可以在app/build/outputs/apk/debug/app-debug.apk中获得apk