Skip to content

Commit

Permalink
Filter out emulator error message (#29)
Browse files Browse the repository at this point in the history
On my computer, `emulator -list-avds` shows an error first and then
lists AVD ids. This change filters it.

```
INFO    | Storing crashdata in: /tmp/android-jgonet/emu-crash-34.1.19.db, detection is enabled for process: 80542
Pixel_3a_API_34_extension_level_7_arm64-v8a
```
  • Loading branch information
jakub-gonet authored Mar 27, 2024
1 parent 79bee5d commit 704daac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions packages/vscode-extension/src/devices/AndroidEmulatorDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,20 @@ export async function createEmulator(displayName: string, systemImage: AndroidSy
available: true, // TODO: there is no easy way to check if emulator is available, we'd need to parse config.ini
} as DeviceInfo;
}

export async function listEmulators() {
const avdDirectory = getOrCreateAvdDirectory();
const UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
async function getAvdIds(avdDirectory: string) {
const { stdout } = await exec(EMULATOR_BINARY, ["-list-avds"], {
env: { ...process.env, ANDROID_AVD_HOME: avdDirectory },
});
const avdIds = stdout.split("\n").filter((avdId) => !!avdId);

// filters out error messages and empty lines
// https://github.com/react-native-community/cli/issues/1801#issuecomment-1980580355
return stdout.split("\n").filter((id) => UUID_REGEX.test(id));
}

export async function listEmulators() {
const avdDirectory = getOrCreateAvdDirectory();
const avdIds = await getAvdIds(avdDirectory);
const systemImages = await getAndroidSystemImages();
return Promise.all(
avdIds.map(async (avdId) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/devices/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DeviceManager implements Disposable, DeviceManagerInterface {

private async loadDevicesInternal() {
const emulators = listEmulators().catch((e) => {
Logger.error("Error fetching emulatos", e);
Logger.error("Error fetching emulators", e);
return [];
});
const simulators = listSimulators().catch((e) => {
Expand Down

0 comments on commit 704daac

Please sign in to comment.