简体   繁体   中英

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

react-native run-android --variant=release

However for a successful release build an android emulator needs to be running. 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.

Is it possible to build a react native application for Android without running an emulator?

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.

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).

The gradlew utility lives inside the android directory and can be used directly like this:

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!

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.

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. After enabling USB debugging, react-native will target your device and install the release apk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM