Skip to content

run-android with specified emulator name #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jayu opened this issue Mar 5, 2020 · 7 comments
Closed

run-android with specified emulator name #1038

jayu opened this issue Mar 5, 2020 · 7 comments

Comments

@jayu
Copy link
Contributor

jayu commented Mar 5, 2020

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

@thymikee
Copy link
Member

thymikee commented Mar 5, 2020

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.

@krizzu
Copy link
Member

krizzu commented Mar 10, 2020

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.

@jayu
Copy link
Contributor Author

jayu commented Mar 12, 2020

@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 :/.

@krizzu
Copy link
Member

krizzu commented Mar 12, 2020

@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:

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

@jayu
Copy link
Contributor Author

jayu commented Mar 12, 2020

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 ✨

@krizzu
Copy link
Member

krizzu commented Mar 12, 2020

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"!

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants