Skip to content
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

Android CLI fails to launch emulator automatically when running yarn android #1801

Closed
UNIDY2002 opened this issue Jan 19, 2023 · 14 comments · Fixed by #1802
Closed

Android CLI fails to launch emulator automatically when running yarn android #1801

UNIDY2002 opened this issue Jan 19, 2023 · 14 comments · Fixed by #1802

Comments

@UNIDY2002
Copy link
Contributor

Environment

System:
    OS: Linux 5.15 Manjaro Linux
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 2.64 GB / 13.51 GB
    Shell: 3.5.1 - /usr/bin/fish
  Binaries:
    Node: 19.2.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 19.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.0 => 0.71.0 
  npmGlobalPackages:
    *react-native*: Not Found

Additional information:

  • Android SDK version 33.0.0
  • Android emulator version 31.2.8.0
  • CLI version 10.0.0

Description

After I execute yarn android, it prints an error message:

error Failed to launch emulator. Reason: The emulator (Pixel_4_API_30) quit before it finished opening. You can try starting the emulator manually from the terminal with: /home/unidy/.sdk/Android/emulator/emulator @Pixel_4_API_30.

I suspect there is something to do with this line: https://github.com/react-native-community/cli/blob/d351048/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts#L27

When port is undefined, the subprocess parameters fall back to [`@${emulatorName}`, '', ''], and the empty strings may be the cause of the problem.

I think it is a regression, because it worked fine before I upgraded react-native to 0.71.

Reproducible Demo

Suggestion for a fix

Change this line: https://github.com/react-native-community/cli/blob/d351048/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts#L27
into:

port ? [`@${emulatorName}`, '-port', `${port}`] : [`@${emulatorName}`]
@adamTrz
Copy link
Collaborator

adamTrz commented Jan 19, 2023

Hi @UNIDY2002 thanks for reporting! Fix is on the way :)

@koralgooll
Copy link

koralgooll commented Nov 25, 2023

In my case the problem was not turned on virtualization in BIOS. So the expo probably was not able to start virtual Pixel device. You can check in Android Virtual Device Manager if you can run it.

@LabGecko
Copy link

LabGecko commented Feb 23, 2024

Still seeing this error. Same basic error to the original poster.

System:
OS: Windows 11 Pro
CPU: AMD Ryzen 7 7735HS with Radeon Graphics 3.20 GHz
Memory: 32.0 GB (27.7 GB usable)
Binaries:
Node: 19.2.0 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.2 - /usr/bin/npm
SDKs: Android SDK: Android 14 (API 34)
IDEs: Android Studio: Hedgehog 2023.1.1 Patch 2 (Build #AI-231.9392.1.2311.11330709)
Languages: Java: 17
npmPackages:
yarn
cli

Note: Starting the emulator in Android Studio gets past this, but just wanted to report that the script to start is still encountering errors.

@codewitharun
Copy link

codewitharun commented Mar 6, 2024

Got 2 solutions from here and here it is working.

  • 1st solution

This bug came from the command line emulator -list-avds

Now this command line add a new log at the first line :

INFO    | Storing crashdata in: /tmp/android-xxx/emu-crash-34.1.18.db, detection is enabled for process: 20206
.Pixel_2_API_31
2.7_QVGA_API_31
3.2_QVGA_ADP2_API_31
3.7_WVGA_Nexus_One_API_31
6.7_Horizontal_Fold-in_API_31
Pixel_2_API_29
Pixel_2_API_33
Pixel_XL_API_31

The problem is that react-native take always the first emulator in this list as default emulator to launch. But now it try to open INFO | Storing crashdata in: /tmp/android-matthias/emu-crash-34.1.18.db, detection is enabled for process: 20206 that is not a emulator name, but just a log info.

To launch the emulator, until a fix, you can still use the command line

emulator @name_of_device

then use the common command :

npm run android

  • ** 2nd solution**

Download Android Emulator (version 33.1.24) Stable from Android Emulator Archive.
Overwrite the existing emulator folder in ~/Library/Android/sdk with the downloaded version.
Run emulator -list-avd manually, confirm the macOS permissions in System Preferences, and then run it a second time to see the INFO log line gone.
If for some reason this doesn't work, consider reverting to an older Stable release from the Android Emulator Archive.

This should help in resolving the emulator crashing issue on Android Studio.

@Mynameisjohndev
Copy link

image

The download links don't appear, I've already tested it on 4 browsers and nothing. If you can view it, please provide the links to all platforms here.

@AYASOFT
Copy link

AYASOFT commented Mar 25, 2024

@Mynameisjohndev here are the direct links as shown on page
Zip files
Windows (64-bit): emulator-windows_x64-11237101.zip (361338481 bytes)
Mac (Intel): emulator-darwin_x64-11237101.zip (317369570 bytes)
Mac (Apple Silicon): emulator-darwin_aarch64-11237101.zip (267679962 bytes)
Linux: emulator-linux_x64-11237101.zip (247516525 bytes)

SHA-256 Checksums
4f21ad916568459a4e38d75755a5cf27c658b844673388e2bfe0f407ae3e8bb9 emulator-windows_x64-11237101.zip
c603ec70071d215f0351fc14ede329504af1608091918dd6804353ac9a9e66e3 emulator-darwin_x64-11237101.zip
8322f2a738cc29eaff26e9de856755ed5a1273d770e01d8347f0d84c8a487696 emulator-darwin_aarch64-11237101.zip
cfd54ce620ad5f9f786682ecad88b8b9da7ac48827d57406cc2a31bb8f6e73fe emulator-linux_x64-11237101.zip

@kadirmetin
Copy link

This error still persists on my computer. Is this the case for all users?

image

@AYASOFT
Copy link

AYASOFT commented Mar 27, 2024

@kadirmetin did you try the solution of @codewitharun
try downloading the previous stable version & replace files after a full restart of the machine.

@haris-dev-72
Copy link

This error still persists on my computer. Is this the case for all users?

image

did you found any solution ???

@kadirmetin
Copy link

This error still persists on my computer. Is this the case for all users?
image

did you found any solution ???

No. The only solution I found was to run the application in the console after running the emulator. But in the past, when I ran the application through the console, it worked in the emulator.

@GNUGradyn
Copy link

Couldn't this utility just be fixed to ignore lines that start with INFO when parsing the emulator output..?

@LabGecko
Copy link

LabGecko commented Jun 3, 2024

The error is now only appearing occasionally for me using VSCode. No idea what is causing the intermittency.

VSCode Version: 1.89.1 (user setup)
Commit: dc96b837cf6bb4af9cd736aa3af08cf8279f7685
Date: 2024-05-07
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Windows 11 Pro x64 ver 23H2 (misreports as Windows_NT x64 10.0.22631 so not sure what other values might be misreporting)

@waohwaohwaoh
Copy link

You can fix this by changing the logic of the getEmulators function in the file node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/tryLaunchEmulator.js
you need changed this line:
return emulatorsOutput.split(_os().default.EOL).filter(name => name !== '');
to:
return emulatorsOutput.split(_os().default.EOL).filter(name => !name.startsWith('INFO') && name !== '');

@Luiyit
Copy link

Luiyit commented Oct 11, 2024

emulatorsOutput.split(

Is a simple way to solve it. Thanks!

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