[英]Is it possible to build a react native application for Android without running an emulator?
When building a react-native project for android you run the following command 在为Android构建本机项目时,运行以下命令
react-native run-android --variant=release
However for a successful release build an android emulator needs to be running. 但是,要成功发行版本,必须运行android模拟器。 If it's not you'll get the following error:
如果不是,则会出现以下错误:
* What went wrong:
Execution failed for task ':app:installRelease'.
> com.android.builder.testing.api.DeviceException: No connected devices!
But I don't want to start an emulator because I'm building the project in a container that doesn't support android emulators. 但是我不想启动模拟器,因为我正在不支持android模拟器的容器中构建项目。
Is it possible to build a react native application for Android without running an emulator? 是否可以在不运行模拟器的情况下为Android构建React本机应用程序?
Note: 注意:
A physical device won't work because I'm working with containers that are running in CircleCI which is a Cloud-based Continuous Integration service. 物理设备无法正常工作,因为我正在使用在CircleCI(基于云的持续集成服务)中运行的容器。
The react-native command line utility wraps another utility called gradlew (which is in fact another wrapper for gradle that will download gradle if it doesn't already exist). react-native命令行实用程序包装了另一个名为gradlew的实用程序(实际上,这是gradle的另一个包装器,如果不存在的话,它将下载gradle)。
The gradlew utility lives inside the android directory and can be used directly like this: gradlew实用程序位于android目录中,可以像这样直接使用:
cd android
./gradlew assembleRelease
So if you're wanting to build a release Android Package (APK) but not run it on an emulator then the above command will work! 因此,如果您想构建一个发行版的Android软件包(APK),但又不想在模拟器上运行它,那么上面的命令将起作用!
You could test your app in browser. 您可以在浏览器中测试您的应用。 But which need some third-party tools, such as https://snack.expo.io/ , and here is a good tutorial about using it.
但是,这需要一些第三方工具,例如https://snack.expo.io/ ,这是有关使用它的很好的教程 。
Why not just use a physical device? 为什么不只使用物理设备?
As long as you have followed these steps : 只要您遵循以下步骤 :
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.
you can enable USB debugging on your device under developer options. 您可以在开发人员选项下在设备上启用USB调试。 After enabling USB debugging,
react-native
will target your device and install the release apk. 启用USB调试后,
react-native
将以您的设备为目标并安装发行版APK。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.