是否可以在不运行模拟器的情况下为 Android 构建一个 react 本机应用程序?



在为 android 构建 react-native 项目时,运行以下命令

react-native run-android --variant=release

但是,要成功发布版本,需要运行 android 模拟器。如果不是,您将收到以下错误:

* What went wrong:
Execution failed for task ':app:installRelease'.
> com.android.builder.testing.api.DeviceException: No connected devices!

但我不想启动模拟器,因为我正在不支持 android 模拟器的容器中构建项目。

是否可以在不运行模拟器的情况下为 Android 构建一个 react 本机应用程序?

注意:

物理设备无法正常工作,因为我正在使用在 CircleCI 中运行的容器,CircleCI 是一种基于云的持续集成服务。

react-native 命令行实用程序包装了另一个名为 gradlew 的实用程序(它实际上是 gradle 的另一个包装器,如果它不存在,它将下载 gradle(。

gradlew 实用程序位于 android 目录中,可以直接像这样使用:

cd android
./gradlew assembleRelease

因此,如果您想构建一个发布的 Android 软件包 (APK( 但不要在模拟器上运行它,那么上面的命令将起作用!

您可以在浏览器中测试您的应用程序。但是这需要一些第三方工具,例如 https://snack.expo.io/,这里有一个关于使用它的好教程。

为什么不直接使用物理设备?

只要您遵循以下步骤:

1. Open the Settings app.
2. (Only on Android 8.0 or higher) Select System.
3. Scroll to the bottom and select About phone.
4. Scroll to the bottom and tap Build number 7 times.
5. Return to the previous screen to find Developer options near the bottom.

您可以在开发人员选项下在设备上启用USB调试。启用USB调试后,react-native将针对您的设备并安装发布apk。

相关内容

最新更新