Cli: run-android with specified emulator name

Created on 5 Mar 2020  ยท  6Comments  ยท  Source: react-native-community/cli

Describe the Feature

be able to run react-native run-android --emulator MyEmulatorName

After shipping #676 we are able to start an android emulator during run-android.
Cli will start a new emulator if there isn't any device available. The drawback of the current solution is that it tries to start the first emulator from the list returned by emulator -list-avds. It would be usefull to be able to run the app on a specific emulator, even if there are other devices connected. It could work similarly to the deviceId flag. We could add an emulator flag followed with the emulator name.

Possible Implementations

This implementation has several edge cases worth discussing, but we will need the following to achieve the goal

Get the emulator names based on deviceId

  1. use adb.getDevices implemented in run-android to get list of currently running devices
  2. Look for deviceIds with pattern emulator-PORT_NUMBER
  3. Map found deviceIds to emulator names using adb -s emulator-PORT_NUMBER emu avd name

Modify tryLauchEmulator to accept the emulator name as a param

Then if an emulator is running, launch the app using tryLaunchAppOnDevice
If the emulator is not running, lunch it and then check once again for adb.devices to get it's deviceId, then tryLaunchAppOnDevice

Related Issues

feature request android

Most helpful comment

Well, seems like I could give it a go then ๐Ÿ˜„

edit: I get that back, that's not how this should be handled ๐Ÿ˜† Going with "possible implementation"!

All 6 comments

Sounds great to have this feature. Would be symmetric to run-ios --simulator. As far as implementation goes, the plan sounds fine. We already have a list available in tryLauchEmulator which we can filter.

Properly installed Android environment comes with emulator command (located in path/to/Android/sdk/emulator/emulator).

emulator -list-avds returns a list of available emulators by their name. Then running emulator -avd EMU_NAME launches that emulator. I think that would simplify necessary steps get it up and running.

@Krizzu we are already using an emulator to run a particular emulator by name. For now, we run the first emulator that is returned by emulator -list-avds.

The problem is we need to be able to run an app on the already booted emulator. To do this, we have to know which of adb devices is our emulator. Our emulator might or might not be running. We need to check that.

The perfect solution would be if adb devices could somehow return name corresponding to a booted emulator. Currently, it just returns emulator-PORT_NUMBER :/.

@jayu

The perfect solution would be if adb devices could somehow return name corresponding to a booted emulator. Currently, it just returns emulator-PORT_NUMBER :/.

You could run
adb -s ADB_EMULATOR_NAME emu avd name
To get its name from AVD manager.

In my case, adb devices gives me emulator-5554. So doing adb -s emulator-5554 emu avd name returns:

OK

The problem is we need to be able to run an app on the already booted emulator.

adb devices returns only running devices (and emulators), so with the check I mention above, we can tell which device is running or not. In case of multiple devices running, I'd install an app on all of them (like iOS is doing now).

Yes, that was exactly my plan! Maybe I didn't describe it clear enough ๐Ÿ˜€ . Now when everything is more or less clear, someone could pick this issue โœจ

Well, seems like I could give it a go then ๐Ÿ˜„

edit: I get that back, that's not how this should be handled ๐Ÿ˜† Going with "possible implementation"!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferrannp picture ferrannp  ยท  4Comments

Jarred-Sumner picture Jarred-Sumner  ยท  3Comments

patrickkempff picture patrickkempff  ยท  4Comments

thymikee picture thymikee  ยท  4Comments

Steffi3rd picture Steffi3rd  ยท  3Comments