From cd5d946b527d2d3e478e7630721c7484bbf781fb Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Mon, 28 Nov 2022 18:39:21 +0100 Subject: [PATCH 1/7] feat: list android devices when building the app --- .../src/commands/runAndroid/index.ts | 47 ++++++- .../commands/runAndroid/listAndroidDevices.ts | 118 ++++++++++++++++++ .../commands/runAndroid/tryLaunchEmulator.ts | 26 ++-- 3 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index dfcff2cc6..6d04acc9d 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -21,7 +21,8 @@ import { CLIError, } from '@react-native-community/cli-tools'; import {getAndroidProject} from '../../config/getAndroidProject'; - +import listAndroidDevices from './listAndroidDevices'; +import tryLaunchEmulator, {launchEmulator} from './tryLaunchEmulator'; export interface Flags { tasks?: Array; variant: string; @@ -33,6 +34,7 @@ export interface Flags { port: number; terminal: string; activeArchOnly: boolean; + listDevices?: boolean; } type AndroidProject = NonNullable; @@ -72,11 +74,46 @@ async function runAndroid(_argv: Array, config: Config, args: Flags) { } // Builds the app and runs it on a connected emulator / device. -function buildAndRun(args: Flags, androidProject: AndroidProject) { +async function buildAndRun(args: Flags, androidProject: AndroidProject) { process.chdir(androidProject.sourceDir); const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew'; const adbPath = getAdbPath(); + if (args.listDevices) { + const device = await listAndroidDevices(); + console.log('device', device); + if (!device) { + return logger.error( + 'Failed to select device, please try to run app without --list-devices command', + ); + } + + if (device.connected) { + return runOnSpecificDevice( + {...args, deviceId: device.deviceId}, + cmd, + adbPath, + androidProject, + ); + } + + try { + console.log('launch emu here....'); + // todo port 5584 can be taken, figure out a way to fix that... + // FIXME: await not woking, emu spawning to late and install command is failing... :| + await tryLaunchEmulator(adbPath, device.readableName, '5584'); + console.log('runOnSpecificDevice'); + // TODO: Get deviceId for launched emulator and then use it + return runOnSpecificDevice( + {...args, deviceId: 'emulator-5584'}, + cmd, + adbPath, + androidProject, + ); + } catch (error) { + throw new CLIError(error); + } + } if (args.deviceId) { return runOnSpecificDevice(args, cmd, adbPath, androidProject); } else { @@ -328,5 +365,11 @@ export default { 'Build native libraries only for the current device architecture for debug builds.', default: false, }, + { + name: '--list-devices', + description: + 'Will list all available Android devices and simulators and let you choos one to run the app', + default: false, + }, ], }; diff --git a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts new file mode 100644 index 000000000..1bac0f486 --- /dev/null +++ b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts @@ -0,0 +1,118 @@ +import {execSync} from 'child_process'; +import adb from './adb'; +import getAdbPath from './getAdbPath'; +import {getEmulators} from './tryLaunchEmulator'; +import os from 'os'; +import prompts from 'prompts'; +import chalk from 'chalk'; +import {CLIError} from '@react-native-community/cli-tools'; + +type DeviceData = { + deviceId: string | undefined; + readableName: string; + connected: boolean; + type: 'emulator' | 'phone'; +}; + +function toPascalCase(value: string) { + return value !== '' ? value[0].toUpperCase() + value.slice(1) : value; +} + +function getEmulatorName(deviceId: string) { + // maybe close it with trycatch block? + const adbPath = getAdbPath(); + const buffer = execSync(`${adbPath} -s ${deviceId} emu avd name`); + + // 1st line should get us emu name + return buffer + .toString() + .split(os.EOL)[0] + .replace(/(\r\n|\n|\r)/gm, '') + .trim(); +} + +function getPhoneName(deviceId: string) { + const adbPath = getAdbPath(); + const buffer = execSync( + `${adbPath} -s ${deviceId} shell getprop | grep ro.product.model`, + ); + return buffer + .toString() + .replace(/[[\]:ro/.product/.model]+/g, '') + .replace(/(\r\n|\n|\r)/gm, '') + .trim(); +} + +async function promptForDeviceSelection( + allDevices: Array, +): Promise { + if (!allDevices.length) { + throw new CLIError( + 'No devices and/or emulators connected. Please create emulator with Android Studio or connect Android device.', + ); + } + const {device} = await prompts({ + type: 'select', + name: 'device', + message: 'Select the device / emulator you want to use', + choices: allDevices.map((d) => ({ + title: `${chalk.bold(`${toPascalCase(d.type)}`)} ${chalk.green( + `${d.readableName}`, + )} (${d.connected ? 'connected' : 'disconnected'})`, + value: d, + })), + min: 1, + }); + + return device; +} + +async function listAndroidDevices() { + const adbPath = getAdbPath(); + const devices = adb.getDevices(adbPath); + + let allDevices: Array = []; + + devices.forEach((deviceId) => { + if (deviceId.includes('emulator')) { + const emulatorData: DeviceData = { + deviceId, + readableName: getEmulatorName(deviceId), + connected: true, + type: 'emulator', + }; + allDevices = [...allDevices, emulatorData]; + } else { + const phoneData: DeviceData = { + deviceId, + readableName: getPhoneName(deviceId), + type: 'phone', + connected: true, + }; + allDevices = [...allDevices, phoneData]; + } + }); + + const emulators = getEmulators(); + + // Find not booted ones: + emulators.forEach((emulatorName) => { + if (allDevices.some((device) => device.readableName === emulatorName)) { + return; + } + const emulatorData: DeviceData = { + deviceId: undefined, + readableName: emulatorName, + type: 'emulator', + connected: false, + }; + allDevices = [...allDevices, emulatorData]; + }); + + console.log('allDevices', allDevices); + + const selectedDevice = await promptForDeviceSelection(allDevices); + return selectedDevice; +} + +export default listAndroidDevices; diff --git a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts index 7f257f72a..763484862 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts @@ -6,7 +6,7 @@ const emulatorCommand = process.env.ANDROID_HOME ? `${process.env.ANDROID_HOME}/emulator/emulator` : 'emulator'; -const getEmulators = () => { +export const getEmulators = () => { try { const emulatorsOutput = execa.sync(emulatorCommand, ['-list-avds']).stdout; return emulatorsOutput.split(os.EOL).filter((name) => name !== ''); @@ -15,12 +15,22 @@ const getEmulators = () => { } }; -const launchEmulator = async (emulatorName: string, adbPath: string) => { +export const launchEmulator = async ( + emulatorName: string, + adbPath: string, + port?: string, +) => { + console.log('emulatorNAme', emulatorName); + console.log('port', port); return new Promise((resolve, reject) => { - const cp = execa(emulatorCommand, [`@${emulatorName}`], { - detached: true, - stdio: 'ignore', - }); + const cp = execa( + emulatorCommand, + [`@${emulatorName}`, port ? '-port' : '', port ? `${port}` : ''], + { + detached: true, + stdio: 'ignore', + }, + ); cp.unref(); const timeout = 30; @@ -56,11 +66,13 @@ const launchEmulator = async (emulatorName: string, adbPath: string) => { export default async function tryLaunchEmulator( adbPath: string, + emulatorName?: string, + port?: string, ): Promise<{success: boolean; error?: string}> { const emulators = getEmulators(); if (emulators.length > 0) { try { - await launchEmulator(emulators[0], adbPath); + await launchEmulator(emulatorName ?? emulators[0], adbPath, port); return {success: true}; } catch (error) { return {success: false, error}; From b18e35f81fdf0bb8aa833c0350d969cb363d0408 Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Mon, 5 Dec 2022 11:54:41 +0100 Subject: [PATCH 2/7] cleanup --- docs/commands.md | 7 ++ .../src/commands/runAndroid/index.ts | 48 +++++++++---- .../commands/runAndroid/listAndroidDevices.ts | 13 +++- .../commands/runAndroid/tryLaunchEmulator.ts | 72 ++++++++++--------- 4 files changed, 93 insertions(+), 47 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 2c4b9e156..fffb9da66 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -379,6 +379,13 @@ Example: `yarn react-native run-android --tasks clean,installDebug`. Build native libraries only for the current device architecture for debug builds. +#### `--list-devices` + +> default: false + +List all available Android devices and simulators and let you choose one to run the app. + + ### `run-ios` Usage: diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index 6d04acc9d..5b82d8841 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -22,7 +22,9 @@ import { } from '@react-native-community/cli-tools'; import {getAndroidProject} from '../../config/getAndroidProject'; import listAndroidDevices from './listAndroidDevices'; -import tryLaunchEmulator, {launchEmulator} from './tryLaunchEmulator'; +import tryLaunchEmulator from './tryLaunchEmulator'; +import chalk from 'chalk'; + export interface Flags { tasks?: Array; variant: string; @@ -73,6 +75,24 @@ async function runAndroid(_argv: Array, config: Config, args: Flags) { }); } +const defaultPort = 5552; +async function getAvailableDevicePort( + port: number = defaultPort, +): Promise { + /** + * The default value is 5554 for the first virtual device instance running on your machine. A virtual device normally occupies a pair of adjacent ports: a console port and an adb port. The console of the first virtual device running on a particular machine uses console port 5554 and adb port 5555. Subsequent instances use port numbers increasing by two. For example, 5556/5557, 5558/5559, and so on. The range is 5554 to 5682, allowing for 64 concurrent virtual devices. + */ + const adbPath = getAdbPath(); + const devices = adb.getDevices(adbPath); + if (port > 5682) { + throw new CLIError('Failed to launch emulator...'); + } + if (devices.some((d) => d.includes(port.toString()))) { + return await getAvailableDevicePort(port + 2); + } + return port; +} + // Builds the app and runs it on a connected emulator / device. async function buildAndRun(args: Flags, androidProject: AndroidProject) { process.chdir(androidProject.sourceDir); @@ -81,7 +101,6 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { const adbPath = getAdbPath(); if (args.listDevices) { const device = await listAndroidDevices(); - console.log('device', device); if (!device) { return logger.error( 'Failed to select device, please try to run app without --list-devices command', @@ -97,21 +116,24 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { ); } - try { - console.log('launch emu here....'); - // todo port 5584 can be taken, figure out a way to fix that... - // FIXME: await not woking, emu spawning to late and install command is failing... :| - await tryLaunchEmulator(adbPath, device.readableName, '5584'); - console.log('runOnSpecificDevice'); - // TODO: Get deviceId for launched emulator and then use it + const port = await getAvailableDevicePort(); + const emulator = `emulator-${port}`; + const result = await tryLaunchEmulator(adbPath, device.readableName, port); + if (result.success) { + logger.info('Successfully launched emulator.'); return runOnSpecificDevice( - {...args, deviceId: 'emulator-5584'}, + {...args, deviceId: emulator}, cmd, adbPath, androidProject, ); - } catch (error) { - throw new CLIError(error); + } else { + logger.error( + `Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}.`, + ); + logger.warn( + 'Please launch an emulator manually or connect a device. Otherwise app may fail to launch.', + ); } } if (args.deviceId) { @@ -368,7 +390,7 @@ export default { { name: '--list-devices', description: - 'Will list all available Android devices and simulators and let you choos one to run the app', + 'Will list all available Android devices and simulators and let you choose one to run the app', default: false, }, ], diff --git a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts index 1bac0f486..7b2d43c43 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts @@ -18,6 +18,11 @@ function toPascalCase(value: string) { return value !== '' ? value[0].toUpperCase() + value.slice(1) : value; } +/** + * + * @param deviceId string + * @returns name of Android emulator + */ function getEmulatorName(deviceId: string) { // maybe close it with trycatch block? const adbPath = getAdbPath(); @@ -31,6 +36,11 @@ function getEmulatorName(deviceId: string) { .trim(); } +/** + * + * @param deviceId string + * @returns Android device name in readable format + */ function getPhoneName(deviceId: string) { const adbPath = getAdbPath(); const buffer = execSync( @@ -97,6 +107,7 @@ async function listAndroidDevices() { // Find not booted ones: emulators.forEach((emulatorName) => { + // skip those already booted if (allDevices.some((device) => device.readableName === emulatorName)) { return; } @@ -109,8 +120,6 @@ async function listAndroidDevices() { allDevices = [...allDevices, emulatorData]; }); - console.log('allDevices', allDevices); - const selectedDevice = await promptForDeviceSelection(allDevices); return selectedDevice; } diff --git a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts index 763484862..4402b1f2f 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts @@ -1,6 +1,6 @@ import os from 'os'; import execa from 'execa'; -import Adb from './adb'; +import adb from './adb'; const emulatorCommand = process.env.ANDROID_HOME ? `${process.env.ANDROID_HOME}/emulator/emulator` @@ -15,51 +15,59 @@ export const getEmulators = () => { } }; -export const launchEmulator = async ( +const launchEmulator = async ( emulatorName: string, adbPath: string, - port?: string, -) => { - console.log('emulatorNAme', emulatorName); - console.log('port', port); - return new Promise((resolve, reject) => { - const cp = execa( - emulatorCommand, - [`@${emulatorName}`, port ? '-port' : '', port ? `${port}` : ''], - { - detached: true, - stdio: 'ignore', - }, - ); - cp.unref(); - const timeout = 30; + port?: number, +): Promise => { + const manualCommand = `${emulatorCommand} @${emulatorName}`; - // Reject command after timeout - const rejectTimeout = setTimeout(() => { - cleanup(); - reject(`Could not start emulator within ${timeout} seconds.`); - }, timeout * 1000); + const cp = execa( + emulatorCommand, + [`@${emulatorName}`, port ? '-port' : '', port ? `${port}` : ''], + { + detached: true, + stdio: 'ignore', + }, + ); + cp.unref(); + const timeout = 30; - const bootCheckInterval = setInterval(() => { - if (Adb.getDevices(adbPath).length > 0) { + return new Promise((resolve, reject) => { + const bootCheckInterval = setInterval(async () => { + const devices = adb.getDevices(adbPath); + const connected = port + ? devices.find((d) => d.includes(`${port}`)) + : devices.length > 0; + if (connected) { cleanup(); - resolve(); + resolve(true); } }, 1000); + // Reject command after timeout + const rejectTimeout = setTimeout(() => { + stopWaitingAndReject( + `It took too long to start and connect with Android emulator: ${emulatorName}. You can try starting the emulator manually from the terminal with: ${manualCommand}`, + ); + }, timeout * 1000); + const cleanup = () => { clearTimeout(rejectTimeout); clearInterval(bootCheckInterval); }; - cp.on('exit', () => { + const stopWaitingAndReject = (message: string) => { cleanup(); - reject('Emulator exited before boot.'); - }); + reject(new Error(message)); + }; - cp.on('error', (error) => { - cleanup(); - reject(error.message); + cp.on('error', ({message}) => stopWaitingAndReject(message)); + + cp.on('exit', () => { + stopWaitingAndReject( + `The emulator (${emulatorName}) quit before it finished opening. You can try starting the emulator manually from the terminal with: ${manualCommand}`, + ); }); }); }; @@ -67,7 +75,7 @@ export const launchEmulator = async ( export default async function tryLaunchEmulator( adbPath: string, emulatorName?: string, - port?: string, + port?: number, ): Promise<{success: boolean; error?: string}> { const emulators = getEmulators(); if (emulators.length > 0) { From 1f7c73ae55084b4b8a2861ff4724c1ac2c435a11 Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Mon, 5 Dec 2022 12:01:32 +0100 Subject: [PATCH 3/7] Warn if both deviceId and listDevices flags are passed --- .../cli-platform-android/src/commands/runAndroid/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index 5b82d8841..c90395904 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -100,6 +100,12 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { const adbPath = getAdbPath(); if (args.listDevices) { + if (args.deviceId) { + logger.warn( + 'Both "deviceId" and "--list-devices" parameters were passed to "run" command. We will list available devices and let you choose from one', + ); + } + const device = await listAndroidDevices(); if (!device) { return logger.error( From e9068c4393c19faf71eb9556431af4e47b881507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Trzci=C5=84ski?= Date: Mon, 5 Dec 2022 19:52:58 +0100 Subject: [PATCH 4/7] Update packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts Co-authored-by: Szymon Rybczak --- .../src/commands/runAndroid/listAndroidDevices.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts index 7b2d43c43..af535df18 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts @@ -48,8 +48,7 @@ function getPhoneName(deviceId: string) { ); return buffer .toString() - .replace(/[[\]:ro/.product/.model]+/g, '') - .replace(/(\r\n|\n|\r)/gm, '') + .replace(/\[ro\.product\.model\]:\s*\[(.*)\]/, '$1') .trim(); } From c243922950ea6536a45ad54ff51a736a6160a320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Trzci=C5=84ski?= Date: Tue, 6 Dec 2022 16:13:05 +0100 Subject: [PATCH 5/7] Update packages/cli-platform-android/src/commands/runAndroid/index.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- packages/cli-platform-android/src/commands/runAndroid/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index 2020dadab..cff49d3fd 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -67,7 +67,7 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { if (args.listDevices) { if (args.deviceId) { logger.warn( - 'Both "deviceId" and "--list-devices" parameters were passed to "run" command. We will list available devices and let you choose from one', + 'Both "deviceId" and "list-devices" parameters were passed to "run" command. We will list available devices and let you choose from one', ); } From b888522843c250e438c64f44c272036d44dbe4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Trzci=C5=84ski?= Date: Tue, 6 Dec 2022 16:14:09 +0100 Subject: [PATCH 6/7] Update packages/cli-platform-android/src/commands/runAndroid/index.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- packages/cli-platform-android/src/commands/runAndroid/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index cff49d3fd..233730658 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -244,7 +244,7 @@ export default { { name: '--list-devices', description: - 'Will list all available Android devices and simulators and let you choose one to run the app', + 'Lists all available Android devices and simulators and let you choose one to run the app', default: false, }, ], From 5056a057fa3a281d2d0d9324b7ed41938f241323 Mon Sep 17 00:00:00 2001 From: Adam Trzcinski Date: Tue, 6 Dec 2022 17:04:37 +0100 Subject: [PATCH 7/7] fix: CR fixes --- .../src/commands/runAndroid/index.ts | 15 ++++++--------- .../src/commands/runAndroid/listAndroidDevices.ts | 1 - .../src/commands/runAndroid/tryLaunchEmulator.ts | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/cli-platform-android/src/commands/runAndroid/index.ts b/packages/cli-platform-android/src/commands/runAndroid/index.ts index 233730658..a582a7b4b 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/index.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/index.ts @@ -73,8 +73,8 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { const device = await listAndroidDevices(); if (!device) { - return logger.error( - 'Failed to select device, please try to run app without --list-devices command', + throw new CLIError( + 'Failed to select device, please try to run app without "list-devices" command.', ); } @@ -88,6 +88,7 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { const port = await getAvailableDevicePort(); const emulator = `emulator-${port}`; + logger.info('Launching emulator...'); const result = await tryLaunchEmulator(adbPath, device.readableName, port); if (result.success) { logger.info('Successfully launched emulator.'); @@ -96,14 +97,10 @@ async function buildAndRun(args: Flags, androidProject: AndroidProject) { adbPath, androidProject, ); - } else { - logger.error( - `Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}.`, - ); - logger.warn( - 'Please launch an emulator manually or connect a device. Otherwise app may fail to launch.', - ); } + throw new CLIError( + `Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}`, + ); } if (args.deviceId) { return runOnSpecificDevice(args, adbPath, androidProject); diff --git a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts index af535df18..74a2c0c6e 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/listAndroidDevices.ts @@ -24,7 +24,6 @@ function toPascalCase(value: string) { * @returns name of Android emulator */ function getEmulatorName(deviceId: string) { - // maybe close it with trycatch block? const adbPath = getAdbPath(); const buffer = execSync(`${adbPath} -s ${deviceId} emu avd name`); diff --git a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts index 4402b1f2f..ba8a41b8b 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts @@ -83,7 +83,7 @@ export default async function tryLaunchEmulator( await launchEmulator(emulatorName ?? emulators[0], adbPath, port); return {success: true}; } catch (error) { - return {success: false, error}; + return {success: false, error: error?.message}; } } return {