Skip to content

feat: launch emulator during run-android #676

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

Merged
merged 10 commits into from
Sep 11, 2019

Conversation

jayu
Copy link
Contributor

@jayu jayu commented Sep 5, 2019

Summary:

This PR resolves #142
TLDR;
Duringreact-native run-android the first of user's emulators will be launched if there is no any running android device/emulator

emulator -list-advs to get a list of emulators
emulator @FIRST_ON_LIST to run the first available emulator

Test Plan:

  • Generate a project with React-native >60.0
  • install CLI from my fork
  • run react-native run-android without launched emulator -> emulator is launching
  • run react-native run-android with launched emulator -> nothing new happens
  • run react-native run-android with device connected -> nothing new happens
  • run react-native run-android without launched emulator, emulator has saved snapshot -> emulator is launching

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@Titozzz
Copy link
Contributor

Titozzz commented Sep 8, 2019

Something that bothers me, there is no point in declaring a function as async just to await its return, you are just overwrapping stuff as it already returns a promise.

@jayu
Copy link
Contributor Author

jayu commented Sep 9, 2019

Thanks, @Titozzz :) It was redundant, fixes.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last batches of adjustments and I think we're good :)
I wonder if we're able to come up with Genymotion (or other custom emulators I don't know of) support as a followup.

@jayu jayu force-pushed the jaysbytes/launch_emulator branch from bc7f1f2 to ba53509 Compare September 11, 2019 12:59
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to test it, but code-wise LGTM 👍 great work @jaysbytes

@thymikee
Copy link
Member

cc @satya164 would you like to give it a try? :)

@thymikee thymikee force-pushed the jaysbytes/launch_emulator branch from d6ea811 to 20bdb48 Compare September 11, 2019 18:23
@thymikee
Copy link
Member

Just tested locally and fixed a bug I encountered. Also adjusted the wording around errors, warnings and infos a bit. Once CI is happy, this is good to go

@thymikee thymikee merged commit c9790eb into react-native-community:master Sep 11, 2019
@jayu
Copy link
Contributor Author

jayu commented Sep 11, 2019

@thymikee thanks for the help with shipping of this awesome feature 😀

@a-c-sreedhar-reddy
Copy link

a-c-sreedhar-reddy commented Sep 12, 2019

Wouldn't it be better if available emulators are shown and asked to select one?

@thymikee
Copy link
Member

@a-c-sreedhar-reddy not sure about that. Current behavior matches what we do for iOS. Maybe it's worth to revisit. Can you please create a proposal for that where we can discuss better UX?

@jsjoeio
Copy link
Contributor

jsjoeio commented Nov 13, 2019

Has this feature been included in a recent release?

I didn't see it mentioned in any of the latest release notes

@Shan7anu
Copy link

Shan7anu commented Dec 5, 2019

@jsjoeio Yes. It's available in the latest release.

C:\Users\Shan7anu\Desktop\RNProjects\Sample>react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...

@jsjoeio
Copy link
Contributor

jsjoeio commented Dec 5, 2019

Woohoo! Thanks for confirming @Shan7anu!

@shon3005
Copy link

shon3005 commented Jan 14, 2023

hello @jayu thanks for adding this feature. unfortunately i seem to be unable to get this to work.

for context, android studio is not running at the time i run npx react-native run-android in terminal.
additional information is that i get this error when i run the above command:
Failed to launch emulator. Reason: The emulator (Pixel_6_API_31) quit before it finished opening. You can try starting the emulator manually from the terminal with: /Library/Android/sdk/emulator/emulator @Pixel_6_API_31.

expected behavior:

  1. android studio boots up
  2. emulator automatically launches

actual behavior:

  1. Build fails with an error com.android.builder.testing.api.DeviceException: No connected devices!

alternatively, i opened up android studio. emulator has not launched yet. i run npx react-native run-android in terminal.
expected behavior:

  1. emulator automatically launches

actual behavior:

  1. Build fails with an error com.android.builder.testing.api.DeviceException: No connected devices!

workaround:
I resorted to manually running my emulator. only then was i able to run the command npx react-native run-android smoothly.

@cetfu
Copy link

cetfu commented Jan 17, 2023

hello @jayu thanks for adding this feature. unfortunately i seem to be unable to get this to work.

for context, android studio is not running at the time i run npx react-native run-android in terminal. additional information is that i get this error when i run the above command: Failed to launch emulator. Reason: The emulator (Pixel_6_API_31) quit before it finished opening. You can try starting the emulator manually from the terminal with: /Library/Android/sdk/emulator/emulator @Pixel_6_API_31.

expected behavior:

1. android studio boots up

2. emulator automatically launches

actual behavior:

1. Build fails with an error `com.android.builder.testing.api.DeviceException: No connected devices!`

alternatively, i opened up android studio. emulator has not launched yet. i run npx react-native run-android in terminal. expected behavior:

1. emulator automatically launches

actual behavior:

1. Build fails with an error `com.android.builder.testing.api.DeviceException: No connected devices!`

workaround: I resorted to manually running my emulator. only then was i able to run the command npx react-native run-android smoothly.

I'm using Linux Mint and getting a similar error

$ npx react-native run-android
info JS server already running.
info Launching emulator...
error Failed to launch emulator. Reason: The emulator (telefon) quit before it finished opening. You can try starting the emulator manually from the terminal with: /home/furkan/Android/Sdk/emulator/emulator @telefon.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
$ emulator -list-avds
telefon

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

Successfully merging this pull request may close these issues.

run-android should also open default simulator, like run-ios
8 participants