cli icon indicating copy to clipboard operation
cli copied to clipboard

Android CLI fails to launch emulator automatically when running `yarn android`

Open UNIDY2002 opened this issue 3 years ago • 14 comments

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}`]

UNIDY2002 avatar Jan 19 '23 02:01 UNIDY2002

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

adamTrz avatar Jan 19 '23 08:01 adamTrz

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.

koralgooll avatar Nov 25 '23 17:11 koralgooll

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.

LabGecko avatar Feb 23 '24 21:02 LabGecko

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.

codewitharun avatar Mar 06 '24 10:03 codewitharun

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.

Mynameisjohndev avatar Mar 15 '24 10:03 Mynameisjohndev

@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

raouf-elmeddah avatar Mar 25 '24 15:03 raouf-elmeddah

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

image

kadirmetin avatar Mar 26 '24 12:03 kadirmetin

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

raouf-elmeddah avatar Mar 27 '24 19:03 raouf-elmeddah

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

image

did you found any solution ???

haris-dev-72 avatar Mar 31 '24 11:03 haris-dev-72

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.

kadirmetin avatar Mar 31 '24 14:03 kadirmetin

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

GNUGradyn avatar May 25 '24 15:05 GNUGradyn

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)

LabGecko avatar Jun 03 '24 16:06 LabGecko

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 !== '');

waohwaohwaoh avatar Sep 27 '24 04:09 waohwaohwaoh

emulatorsOutput.split(

Is a simple way to solve it. Thanks!

Luiyit avatar Oct 11 '24 12:10 Luiyit