如何在 React Native 中生成 Android 应用程序包?

Fai*_*har 7 android apk react-native

我使用 React Native 的官方文档来构建 apk 文件。所有其他程序都运行良好,但创建 aab 文件对我不起作用。我使用了以下命令 cd android && ./gradlew bundleRelease 但它在 Windows 上不起作用。它只是给我错误“。不被识别”

小智 14

cd android/
./gradlew bundleRelease
Run Code Online (Sandbox Code Playgroud)

  • 虽然此代码可以回答问题,但提供有关如何和/或为何解决问题的附加上下文将提高​​答案的长期价值。您可以在帮助中心找到有关如何编写良好答案的更多信息:https://stackoverflow.com/help/how-to-answer。祝你好运 (2认同)

小智 12

创建主要的 js 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/
Run Code Online (Sandbox Code Playgroud)

然后运行 ​​cd android && ./gradlew assembleRelease

  • 对于react-native版本0.57及以上,捆绑输出路径应该是:`android/app/build/ generated/assets/react/debug/index.android.js` 请参阅[react-native cli文档](https://github .com/react-native-community/cli/blob/master/docs/commands.md#--bundle-output-string)了解更多详细信息。 (2认同)

Raj*_*jan 6

以下命令在 mac 中完美运行

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle && cd ./android && ./gradlew app:assembleRelease
Run Code Online (Sandbox Code Playgroud)