From 93e8a4eaaff1d56ad700f19a709c7a5e3f09c726 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 27 Nov 2023 18:31:51 +0100 Subject: [PATCH 01/13] extract android device decision from running --- .../appConfigs/harness/renative.json | 6 ++-- packages/app-harness/package.json | 2 +- packages/sdk-android/src/runner.ts | 32 ++++++++++++------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/app-harness/appConfigs/harness/renative.json b/packages/app-harness/appConfigs/harness/renative.json index e4fdeeb0ca..a44385f06f 100644 --- a/packages/app-harness/appConfigs/harness/renative.json +++ b/packages/app-harness/appConfigs/harness/renative.json @@ -9,7 +9,7 @@ "description": "Cross-platform application project based on ReNative", "buildSchemes": { "debug": { - "id": "renative.helloworld.debug", + "id": "renative.helloworld.debugs", "title": "ReNative Debug" }, "test": { @@ -44,7 +44,9 @@ }, "ios": { "buildSchemes": { - "debug": {} + "debug": { + "teamID": "BTT4G9WRN2" + } } }, "tvos": { diff --git a/packages/app-harness/package.json b/packages/app-harness/package.json index 33218bd4fd..5792ac19f8 100644 --- a/packages/app-harness/package.json +++ b/packages/app-harness/package.json @@ -54,7 +54,7 @@ "@rnv/engine-rn-next": "1.0.0-rc.0", "@rnv/engine-rn-tvos": "1.0.0-rc.0", "@rnv/engine-rn-web": "1.0.0-rc.0", - "@rnv/template-starter": "1.0.0-rc.0", + "@rnv/template-starter": "^1.0.0-rc.0", "@types/react": "18.2.22", "@types/react-dom": "18.2.7", "@types/react-native": "0.72.2", diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 6d5b1fdb02..ed6d5dc75f 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -75,13 +75,14 @@ export const packageAndroid = async (_c: Context) => { return true; }; -export const runAndroid = async (c: Context) => { +export const getDeviceToRunOn = async (c: Context) => { + logTask('getDeviceToRunOn'); + + if (!c.platform) return; + const { target } = c.program; const { platform } = c; const defaultTarget = c.runtime.target; - logTask('runAndroid', `target:${target} default:${defaultTarget}`); - - if (!platform) return; await resetAdb(c); @@ -126,12 +127,12 @@ export const runAndroid = async (c: Context) => { }); if (response.chosenEmulator) { const dev = activeDevices.find((d) => d.name === response.chosenEmulator); - await runReactNativeAndroid(c, platform, dev); + return dev; } } else { await askForNewEmulator(c, platform); - const devices = await checkForActiveEmulator(c); - await runReactNativeAndroid(c, platform, devices); + const device = await checkForActiveEmulator(c); + return device; } }; @@ -141,11 +142,11 @@ export const runAndroid = async (c: Context) => { const foundDevice = devicesAndEmulators.find((d) => d.udid.includes(target) || d.name.includes(target)); if (foundDevice) { if (foundDevice.isActive) { - await runReactNativeAndroid(c, platform, foundDevice); + return foundDevice; } else { await launchAndroidSimulator(c, foundDevice, true); const device = await checkForActiveEmulator(c); - await runReactNativeAndroid(c, platform, device); + return device; } } else { await askWhereToRun(); @@ -154,7 +155,7 @@ export const runAndroid = async (c: Context) => { // Only one that is active, running on that one const dv = activeDevices[0]; logInfo(`Found device ${dv.name}:${dv.udid}!`); - await runReactNativeAndroid(c, platform, dv); + return dv; } else if (defaultTarget) { // neither a target nor an active device is found, revert to default target if available logDebug('Default target used', defaultTarget); @@ -167,13 +168,22 @@ export const runAndroid = async (c: Context) => { } else { await launchAndroidSimulator(c, foundDevice, true); const device = await checkForActiveEmulator(c); - await runReactNativeAndroid(c, platform, device); + return device; } } else { // we don't know what to do, ask the user logDebug('Target not provided, asking where to run'); await askWhereToRun(); } +} + +export const runAndroid = async (c: Context) => { + logTask('runAndroid', `target:${target} default:${defaultTarget}`); + const { platform } = c; + + if (!platform) return; + + await runReactNativeAndroid(c, platform, device); }; const _checkSigningCerts = async (c: Context) => { From fc947c4f5abac18f52a4b8dc59f0dcba001b1c33 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 27 Nov 2023 20:41:57 +0100 Subject: [PATCH 02/13] rework device logic --- .../engine-rn-tvos/src/tasks/task.rnv.run.ts | 12 +++-- packages/engine-rn/src/tasks/task.rnv.run.ts | 12 +++-- packages/sdk-android/src/deviceManager.ts | 6 ++- packages/sdk-android/src/runner.ts | 46 ++++++++----------- .../sdk-apple/src/__tests__/index.test.ts | 10 ++-- packages/sdk-apple/src/runner.ts | 4 +- 6 files changed, 46 insertions(+), 44 deletions(-) diff --git a/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts b/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts index e93e62c023..1d8ff53c14 100644 --- a/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn-tvos/src/tasks/task.rnv.run.ts @@ -14,8 +14,8 @@ import { executeOrSkipTask, shouldSkipTask, } from '@rnv/core'; -import { packageAndroid, runAndroid } from '@rnv/sdk-android'; -import { runXcodeProject, getDeviceToRunOn } from '@rnv/sdk-apple'; +import { packageAndroid, runAndroid, getAndroidDeviceToRunOn } from '@rnv/sdk-android'; +import { runXcodeProject, getIosDeviceToRunOn } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '@rnv/sdk-react-native'; export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { @@ -34,21 +34,23 @@ export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { switch (platform) { case ANDROID_TV: case FIRE_TV: + // eslint-disable-next-line no-case-declarations + const runDevice = await getAndroidDeviceToRunOn(c); if (!c.program.only) { await startBundlerIfRequired(c, TASK_RUN, originTask); if (bundleAssets) { await packageAndroid(c); } - await runAndroid(c); + await runAndroid(c, runDevice!); if (!bundleAssets) { logSummary('BUNDLER STARTED'); } return waitForBundlerIfRequired(c); } - return runAndroid(c); + return runAndroid(c, runDevice!); case TVOS: // eslint-disable-next-line no-case-declarations - const runDeviceArgs = await getDeviceToRunOn(c); + const runDeviceArgs = await getIosDeviceToRunOn(c); if (!c.program.only) { await startBundlerIfRequired(c, TASK_RUN, originTask); await runXcodeProject(c, runDeviceArgs); diff --git a/packages/engine-rn/src/tasks/task.rnv.run.ts b/packages/engine-rn/src/tasks/task.rnv.run.ts index 0bd41dceb3..bc4e997c1f 100644 --- a/packages/engine-rn/src/tasks/task.rnv.run.ts +++ b/packages/engine-rn/src/tasks/task.rnv.run.ts @@ -17,8 +17,8 @@ import { getConfigProp, logSummary, } from '@rnv/core'; -import { packageAndroid, runAndroid } from '@rnv/sdk-android'; -import { runXcodeProject, getDeviceToRunOn } from '@rnv/sdk-apple'; +import { packageAndroid, runAndroid, getAndroidDeviceToRunOn } from '@rnv/sdk-android'; +import { runXcodeProject, getIosDeviceToRunOn } from '@rnv/sdk-apple'; import { startBundlerIfRequired, waitForBundlerIfRequired } from '@rnv/sdk-react-native'; export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { @@ -37,7 +37,7 @@ export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { case IOS: case MACOS: // eslint-disable-next-line no-case-declarations - const runDeviceArgs = await getDeviceToRunOn(c); + const runDeviceArgs = await getIosDeviceToRunOn(c); if (!c.program.only) { await startBundlerIfRequired(c, TASK_RUN, originTask); await runXcodeProject(c, runDeviceArgs); @@ -51,18 +51,20 @@ export const taskRnvRun: RnvTaskFn = async (c, parentTask, originTask) => { case ANDROID_TV: case FIRE_TV: case ANDROID_WEAR: + // eslint-disable-next-line no-case-declarations + const runDevice = await getAndroidDeviceToRunOn(c); if (!c.program.only) { await startBundlerIfRequired(c, TASK_RUN, originTask); if (bundleAssets || platform === ANDROID_WEAR) { await packageAndroid(c); } - await runAndroid(c); + await runAndroid(c, runDevice!); if (!bundleAssets) { logSummary('BUNDLER STARTED'); } return waitForBundlerIfRequired(c); } - return runAndroid(c); + return runAndroid(c, runDevice!); default: return logErrorPlatform(c); } diff --git a/packages/sdk-android/src/deviceManager.ts b/packages/sdk-android/src/deviceManager.ts index 1dc71fe42e..31e50d0599 100644 --- a/packages/sdk-android/src/deviceManager.ts +++ b/packages/sdk-android/src/deviceManager.ts @@ -26,6 +26,7 @@ import { waitForExecCLI, inquirerPrompt, RnvPlatform, + executeAsync, } from '@rnv/core'; import { CLI_ANDROID_EMULATOR, CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_SDKMANAGER } from './constants'; @@ -79,7 +80,10 @@ export const launchAndroidSimulator = async ( if (newTarget) { const actualTarget = typeof newTarget === 'string' ? newTarget : newTarget.name; if (isIndependentThread) { - execCLI(c, CLI_ANDROID_EMULATOR, `-avd "${actualTarget}"`, { + executeAsync(c.cli[CLI_ANDROID_EMULATOR]!, { + rawCommand: { + args: [`-avd '${actualTarget}'`, '> /dev/null', '&'], + }, detached: isIndependentThread, }).catch((err) => { if (err.includes && err.includes('WHPX')) { diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index ed6d5dc75f..468bdf2240 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -54,7 +54,7 @@ import { import { parseGradleWrapperSync } from './gradleWrapperParser'; import { parseValuesStringsSync, injectPluginXmlValuesSync, parseValuesColorsSync } from './xmlValuesParser'; import { ejectGradleProject } from './ejector'; -import { Context } from './types'; +import { AndroidDevice, Context } from './types'; import { resetAdb, getAndroidTargets, @@ -75,14 +75,14 @@ export const packageAndroid = async (_c: Context) => { return true; }; -export const getDeviceToRunOn = async (c: Context) => { - logTask('getDeviceToRunOn'); +export const getAndroidDeviceToRunOn = async (c: Context) => { + const defaultTarget = c.runtime.target; + logTask('getAndroidDeviceToRunOn', `default:${defaultTarget}`); if (!c.platform) return; const { target } = c.program; const { platform } = c; - const defaultTarget = c.runtime.target; await resetAdb(c); @@ -90,12 +90,7 @@ export const getDeviceToRunOn = async (c: Context) => { await connectToWifiDevice(c, target); } - let devicesAndEmulators; - try { - devicesAndEmulators = await getAndroidTargets(c, false, false, c.program.device !== undefined); - } catch (e) { - return Promise.reject(e); - } + const devicesAndEmulators = await getAndroidTargets(c, false, false, c.program.device !== undefined); const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); @@ -113,8 +108,6 @@ export const getDeviceToRunOn = async (c: Context) => { }); if (response.chosenEmulator) { await launchAndroidSimulator(c, response.chosenEmulator, true); - const devices = await checkForActiveEmulator(c); - await runReactNativeAndroid(c, platform, devices); } } else if (activeDevices.length > 1) { const devicesString = composeDevicesArray(activeDevices); @@ -131,9 +124,10 @@ export const getDeviceToRunOn = async (c: Context) => { } } else { await askForNewEmulator(c, platform); - const device = await checkForActiveEmulator(c); - return device; } + + const device = await checkForActiveEmulator(c); + return device; }; if (target) { @@ -145,17 +139,16 @@ export const getDeviceToRunOn = async (c: Context) => { return foundDevice; } else { await launchAndroidSimulator(c, foundDevice, true); - const device = await checkForActiveEmulator(c); - return device; } } else { - await askWhereToRun(); + logDebug('Target not found, asking where to run'); + return askWhereToRun(); } } else if (activeDevices.length === 1) { // Only one that is active, running on that one - const dv = activeDevices[0]; - logInfo(`Found device ${dv.name}:${dv.udid}!`); - return dv; + const activeDevice = activeDevices[0]; + logInfo(`Found active device ${activeDevice.name}:${activeDevice.udid}!`); + return activeDevice; } else if (defaultTarget) { // neither a target nor an active device is found, revert to default target if available logDebug('Default target used', defaultTarget); @@ -164,21 +157,22 @@ export const getDeviceToRunOn = async (c: Context) => { ); if (!foundDevice) { logDebug('Target not provided, asking where to run'); - await askWhereToRun(); + return askWhereToRun(); } else { await launchAndroidSimulator(c, foundDevice, true); - const device = await checkForActiveEmulator(c); - return device; } } else { // we don't know what to do, ask the user logDebug('Target not provided, asking where to run'); - await askWhereToRun(); + return askWhereToRun(); } + + const device = await checkForActiveEmulator(c); + return device; } -export const runAndroid = async (c: Context) => { - logTask('runAndroid', `target:${target} default:${defaultTarget}`); +export const runAndroid = async (c: Context, device: AndroidDevice) => { + logTask('runAndroid', `target:${device.udid}`); const { platform } = c; if (!platform) return; diff --git a/packages/sdk-apple/src/__tests__/index.test.ts b/packages/sdk-apple/src/__tests__/index.test.ts index ae35b1e320..bdc3935143 100644 --- a/packages/sdk-apple/src/__tests__/index.test.ts +++ b/packages/sdk-apple/src/__tests__/index.test.ts @@ -1,6 +1,6 @@ import { createRnvApi, createRnvContext } from '@rnv/core'; import type { PromptParams } from "@rnv/core"; -import { getDeviceToRunOn } from '../runner'; +import { getIosDeviceToRunOn } from '../runner'; import { simctlSimJson, xctraceDevices } from '../__mocks__/data'; beforeEach(() => { @@ -14,7 +14,7 @@ afterEach(() => { jest.clearAllMocks(); }); -describe('getDeviceToRunOn', () => { +describe('getIosDeviceToRunOn', () => { it('should return a device to run on with pick', async () => { const ctx = getContext(); @@ -39,7 +39,7 @@ describe('getDeviceToRunOn', () => { } }); - const deviceArgs = await getDeviceToRunOn(ctx); + const deviceArgs = await getIosDeviceToRunOn(ctx); expect(executeAsync).toHaveBeenCalledTimes(2); expect(deviceArgs).toBe('--simulator iPhone\\ 14'); }); @@ -65,7 +65,7 @@ describe('getDeviceToRunOn', () => { } }); - const deviceArgs = await getDeviceToRunOn(ctx); + const deviceArgs = await getIosDeviceToRunOn(ctx); expect(executeAsync).toHaveBeenCalledTimes(2); expect(deviceArgs).toBe('--simulator iPhone\\ SE\\ (3rd\\ generation)'); }); @@ -80,7 +80,7 @@ describe('getDeviceToRunOn', () => { .mockReturnValueOnce(Promise.resolve(xctraceDevices)) .mockReturnValueOnce(Promise.resolve(JSON.stringify(simctlSimJson))); - const deviceArgs = await getDeviceToRunOn(ctx); + const deviceArgs = await getIosDeviceToRunOn(ctx); expect(executeAsync).toHaveBeenCalledTimes(2); expect(deviceArgs).toContain('--simulator'); // expect(deviceArgs).toBe('--simulator iPhone\\ 14\\ Plus'); // FIXME: This is failing diff --git a/packages/sdk-apple/src/runner.ts b/packages/sdk-apple/src/runner.ts index a4eb5be910..102e288e12 100644 --- a/packages/sdk-apple/src/runner.ts +++ b/packages/sdk-apple/src/runner.ts @@ -197,8 +197,8 @@ const copyAppleAssets = (c: Context, platform: RnvPlatform, appFolderName: strin resolve(); }); -export const getDeviceToRunOn = async (c: Context) => { - logTask('getDeviceToRunOn'); +export const getIosDeviceToRunOn = async (c: Context) => { + logTask('getIosDeviceToRunOn'); if (!c.platform) return; From bd3648d68fe8f5157a684434e4a6811bae6ed722 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 27 Nov 2023 23:19:52 +0100 Subject: [PATCH 03/13] silence avd start --- packages/sdk-android/src/deviceManager.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/sdk-android/src/deviceManager.ts b/packages/sdk-android/src/deviceManager.ts index 31e50d0599..4f4f899dec 100644 --- a/packages/sdk-android/src/deviceManager.ts +++ b/packages/sdk-android/src/deviceManager.ts @@ -26,7 +26,6 @@ import { waitForExecCLI, inquirerPrompt, RnvPlatform, - executeAsync, } from '@rnv/core'; import { CLI_ANDROID_EMULATOR, CLI_ANDROID_ADB, CLI_ANDROID_AVDMANAGER, CLI_ANDROID_SDKMANAGER } from './constants'; @@ -80,11 +79,9 @@ export const launchAndroidSimulator = async ( if (newTarget) { const actualTarget = typeof newTarget === 'string' ? newTarget : newTarget.name; if (isIndependentThread) { - executeAsync(c.cli[CLI_ANDROID_EMULATOR]!, { - rawCommand: { - args: [`-avd '${actualTarget}'`, '> /dev/null', '&'], - }, + execCLI(c, CLI_ANDROID_EMULATOR, `-avd "${actualTarget}"`, { detached: isIndependentThread, + silent: true, }).catch((err) => { if (err.includes && err.includes('WHPX')) { logWarning(err); @@ -99,6 +96,7 @@ export const launchAndroidSimulator = async ( } return execCLI(c, CLI_ANDROID_EMULATOR, `-avd "${actualTarget}"`, { detached: isIndependentThread, + silent: true, }); } return Promise.reject('No simulator -t target name specified!'); From e805007851f4d8ca3485ff79e875d1392b48cacd Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 27 Nov 2023 23:27:45 +0100 Subject: [PATCH 04/13] remove testing code --- packages/app-harness/appConfigs/harness/renative.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/app-harness/appConfigs/harness/renative.json b/packages/app-harness/appConfigs/harness/renative.json index a44385f06f..e4fdeeb0ca 100644 --- a/packages/app-harness/appConfigs/harness/renative.json +++ b/packages/app-harness/appConfigs/harness/renative.json @@ -9,7 +9,7 @@ "description": "Cross-platform application project based on ReNative", "buildSchemes": { "debug": { - "id": "renative.helloworld.debugs", + "id": "renative.helloworld.debug", "title": "ReNative Debug" }, "test": { @@ -44,9 +44,7 @@ }, "ios": { "buildSchemes": { - "debug": { - "teamID": "BTT4G9WRN2" - } + "debug": {} } }, "tvos": { From a711aed99df18f74a6b8c7a8c05bdefee7ac1e22 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 27 Nov 2023 23:54:43 +0100 Subject: [PATCH 05/13] remove duplicate emulators --- packages/sdk-android/src/deviceManager.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sdk-android/src/deviceManager.ts b/packages/sdk-android/src/deviceManager.ts index 4f4f899dec..e0466ee8cc 100644 --- a/packages/sdk-android/src/deviceManager.ts +++ b/packages/sdk-android/src/deviceManager.ts @@ -509,7 +509,11 @@ const _parseDevicesResult = async ( } if (avdDetails) { - devices.push(device); + // exclude duplicate sims (running ones + avdconfig) + const potentialDuplicate = devices.find((v) => v.name === device.name); + if (!potentialDuplicate || potentialDuplicate.isDevice) { + devices.push(device); + } } }) ); From eed74a68c48f689c9e497a1c2437b5fe4e0c2ae4 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Tue, 28 Nov 2023 22:27:47 +0100 Subject: [PATCH 06/13] fix empty target, don't pick first device regardless of what's happening --- packages/sdk-android/src/runner.ts | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 468bdf2240..fd73880ac2 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -86,7 +86,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { await resetAdb(c); - if (target && net.isIP(target.split(':')[0])) { + if (target && typeof target === 'string' && net.isIP(target.split(':')[0])) { await connectToWifiDevice(c, target); } @@ -106,8 +106,11 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { message: 'What emulator would you like to start?', choices, }); + if (response.chosenEmulator) { await launchAndroidSimulator(c, response.chosenEmulator, true); + const device = await checkForActiveEmulator(c); + return device; } } else if (activeDevices.length > 1) { const devicesString = composeDevicesArray(activeDevices); @@ -124,10 +127,9 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { } } else { await askForNewEmulator(c, platform); + const device = await checkForActiveEmulator(c); + return device; } - - const device = await checkForActiveEmulator(c); - return device; }; if (target) { @@ -137,13 +139,13 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { if (foundDevice) { if (foundDevice.isActive) { return foundDevice; - } else { - await launchAndroidSimulator(c, foundDevice, true); - } - } else { - logDebug('Target not found, asking where to run'); - return askWhereToRun(); + } + await launchAndroidSimulator(c, foundDevice, true); + const device = await checkForActiveEmulator(c); + return device; } + logDebug('Target not found, asking where to run'); + return askWhereToRun(); } else if (activeDevices.length === 1) { // Only one that is active, running on that one const activeDevice = activeDevices[0]; @@ -155,20 +157,21 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { const foundDevice = devicesAndEmulators.find( (d) => d.udid.includes(defaultTarget) || d.name.includes(defaultTarget) ); + if (!foundDevice) { logDebug('Target not provided, asking where to run'); return askWhereToRun(); - } else { + } else if (!foundDevice.isActive) { await launchAndroidSimulator(c, foundDevice, true); + const device = await checkForActiveEmulator(c); + return device; } + return foundDevice; } else { // we don't know what to do, ask the user logDebug('Target not provided, asking where to run'); return askWhereToRun(); } - - const device = await checkForActiveEmulator(c); - return device; } export const runAndroid = async (c: Context, device: AndroidDevice) => { From 2ec60f76394312757235d1e63b3ab0a058bb2876 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 29 Nov 2023 11:56:33 +0100 Subject: [PATCH 07/13] don't fall back to create emu if there's one active device --- packages/sdk-android/src/runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index fd73880ac2..24e0994312 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -112,7 +112,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { const device = await checkForActiveEmulator(c); return device; } - } else if (activeDevices.length > 1) { + } else if (activeDevices.length >= 1) { const devicesString = composeDevicesArray(activeDevices); const choices = devicesString; const response = await inquirerPrompt({ From dee469d0cd530376142459cf2504a84bae2cbacc Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Mon, 4 Dec 2023 14:48:21 +0100 Subject: [PATCH 08/13] sims behaving as documented, wip --- packages/app-harness/package.json | 2 +- packages/sdk-android/src/deviceManager.ts | 2 +- packages/sdk-android/src/runner.ts | 13 +++++++++++-- packages/sdk-tizen/src/__tests__/runner.test.ts | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/app-harness/package.json b/packages/app-harness/package.json index fd3bdc317d..803ef3bc27 100644 --- a/packages/app-harness/package.json +++ b/packages/app-harness/package.json @@ -51,7 +51,7 @@ "@rnv/engine-rn-next": "1.0.0-rc.1", "@rnv/engine-rn-tvos": "1.0.0-rc.1", "@rnv/engine-rn-web": "1.0.0-rc.1", - "@rnv/template-starter": "1.0.0-rc.1", + "@rnv/template-starter": "^1.0.0-rc.1", "@types/react": "18.2.22", "@types/react-dom": "18.2.7", "@types/react-native": "0.72.2", diff --git a/packages/sdk-android/src/deviceManager.ts b/packages/sdk-android/src/deviceManager.ts index e0466ee8cc..255b795a8a 100644 --- a/packages/sdk-android/src/deviceManager.ts +++ b/packages/sdk-android/src/deviceManager.ts @@ -469,7 +469,7 @@ const _parseDevicesResult = async ( } } - if (avdsString) { + if (avdsString && !deviceOnly) { const avdLines = avdsString.trim().split(/\r?\n/); logDebug('_parseDevicesResult 7', { avdLines }); diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 24e0994312..093e7d8685 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -81,7 +81,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { if (!c.platform) return; - const { target } = c.program; + const { target, device } = c.program; const { platform } = c; await resetAdb(c); @@ -90,13 +90,19 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { await connectToWifiDevice(c, target); } - const devicesAndEmulators = await getAndroidTargets(c, false, false, c.program.device !== undefined); + const devicesAndEmulators = await getAndroidTargets(c, false, false, device !== undefined); const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); + console.log('devicesAndEmulators', devicesAndEmulators); + const askWhereToRun = async () => { if (activeDevices.length === 0 && inactiveDevices.length > 0) { + // No device active and device param is passed, exiting + if (c.program.device) { + return logError('No active devices found, please connect one or remove the device argument', true) + } // No device active, but there are emulators created const devicesString = composeDevicesArray(inactiveDevices); const choices = devicesString; @@ -126,6 +132,9 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { return dev; } } else { + if (c.program.device) { + return logError('No active devices found, please connect one or remove the device argument', true) + } await askForNewEmulator(c, platform); const device = await checkForActiveEmulator(c); return device; diff --git a/packages/sdk-tizen/src/__tests__/runner.test.ts b/packages/sdk-tizen/src/__tests__/runner.test.ts index 9d2f2afe97..40e7912019 100644 --- a/packages/sdk-tizen/src/__tests__/runner.test.ts +++ b/packages/sdk-tizen/src/__tests__/runner.test.ts @@ -1,4 +1,4 @@ -import { createRnvApi, createRnvContext, execCLI, getContext } from '@rnv/core'; +import { createRnvApi, createRnvContext, getContext } from '@rnv/core'; import { configureTizenGlobal, checkTizenStudioCert } from '../runner'; import path from 'path'; From 38f4edd1c7b22fc615046f1a91868ea0de86c528 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 6 Dec 2023 10:40:09 +0100 Subject: [PATCH 09/13] removed cl --- packages/sdk-android/src/runner.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 093e7d8685..bc42d4123d 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -95,8 +95,6 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); - console.log('devicesAndEmulators', devicesAndEmulators); - const askWhereToRun = async () => { if (activeDevices.length === 0 && inactiveDevices.length > 0) { // No device active and device param is passed, exiting From c4dc40f0d86ca32d482eb275fb70768c0b9f35bd Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 6 Dec 2023 14:42:19 +0100 Subject: [PATCH 10/13] -d device, no -d sim, don't care about active device/sim --- packages/sdk-android/src/runner.ts | 38 ++++++++++-------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index bc42d4123d..42089685d3 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -24,7 +24,6 @@ import { logTask, logWarning, logDebug, - logInfo, logSuccess, logRaw, logError, @@ -90,20 +89,22 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { await connectToWifiDevice(c, target); } - const devicesAndEmulators = await getAndroidTargets(c, false, false, device !== undefined); + const devicesAndEmulators = await getAndroidTargets(c, !device, device, !!device); const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); const askWhereToRun = async () => { - if (activeDevices.length === 0 && inactiveDevices.length > 0) { + if (activeDevices.length || inactiveDevices.length) { // No device active and device param is passed, exiting - if (c.program.device) { + if (c.program.device && !activeDevices.length) { return logError('No active devices found, please connect one or remove the device argument', true) } - // No device active, but there are emulators created - const devicesString = composeDevicesArray(inactiveDevices); - const choices = devicesString; + + const activeString = composeDevicesArray(activeDevices); + const inactiveString = composeDevicesArray(inactiveDevices); + + const choices = [...activeString, ...inactiveString]; const response = await inquirerPrompt({ name: 'chosenEmulator', type: 'list', @@ -112,26 +113,16 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { }); if (response.chosenEmulator) { + const dev = activeDevices.find((d) => d.name === response.chosenEmulator); + if (dev) return dev; + await launchAndroidSimulator(c, response.chosenEmulator, true); const device = await checkForActiveEmulator(c); return device; } - } else if (activeDevices.length >= 1) { - const devicesString = composeDevicesArray(activeDevices); - const choices = devicesString; - const response = await inquirerPrompt({ - name: 'chosenEmulator', - type: 'list', - message: 'Where would you like to run your app?', - choices, - }); - if (response.chosenEmulator) { - const dev = activeDevices.find((d) => d.name === response.chosenEmulator); - return dev; - } } else { if (c.program.device) { - return logError('No active devices found, please connect one or remove the device argument', true) + return logError('No active devices found, please connect one or remove the device argument', true); } await askForNewEmulator(c, platform); const device = await checkForActiveEmulator(c); @@ -153,11 +144,6 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { } logDebug('Target not found, asking where to run'); return askWhereToRun(); - } else if (activeDevices.length === 1) { - // Only one that is active, running on that one - const activeDevice = activeDevices[0]; - logInfo(`Found active device ${activeDevice.name}:${activeDevice.udid}!`); - return activeDevice; } else if (defaultTarget) { // neither a target nor an active device is found, revert to default target if available logDebug('Default target used', defaultTarget); From ecc660ae51367a9252b98ae4fd18c3484f283f27 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 6 Dec 2023 14:58:06 +0100 Subject: [PATCH 11/13] show devices and sims regardless with -t --- packages/sdk-android/src/runner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 42089685d3..b97df12b3a 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -89,7 +89,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { await connectToWifiDevice(c, target); } - const devicesAndEmulators = await getAndroidTargets(c, !device, device, !!device); + const devicesAndEmulators = await getAndroidTargets(c, false, false, !!device); const activeDevices = devicesAndEmulators.filter((d) => d.isActive); const inactiveDevices = devicesAndEmulators.filter((d) => !d.isActive); From 11b8e0122ce73ce0632b77a051ae0fa1e6c8f4bd Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 6 Dec 2023 17:04:24 +0100 Subject: [PATCH 12/13] don't pick device when looking for emu, specify which emu to wait for --- packages/sdk-android/src/deviceManager.ts | 18 +++++++++++++----- packages/sdk-android/src/runner.ts | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/sdk-android/src/deviceManager.ts b/packages/sdk-android/src/deviceManager.ts index 255b795a8a..578f0defed 100644 --- a/packages/sdk-android/src/deviceManager.ts +++ b/packages/sdk-android/src/deviceManager.ts @@ -624,7 +624,7 @@ const waitForEmulatorToBeReady = (c: RnvContext, emulator: string) => return res; }); -export const checkForActiveEmulator = (c: RnvContext) => +export const checkForActiveEmulator = (c: RnvContext, emulatorName?: string) => new Promise((resolve, reject) => { logTask('checkForActiveEmulator'); const { platform } = c; @@ -643,11 +643,19 @@ export const checkForActiveEmulator = (c: RnvContext) => running = true; getAndroidTargets(c, false, true, false) .then(async (v) => { - logDebug('Available devices after filtering', v); - if (v.length > 0) { - logSuccess(`Found active emulator! ${chalk().white(v[0].udid)}. Will use it`); + const simsOnly = v.filter((device) => !device.isDevice); + logDebug('Available devices after filtering', simsOnly); + if (emulatorName) { + const found = simsOnly.find((v) => v.name === emulatorName); + if (found) { + logSuccess(`Found active emulator! ${chalk().white(found.udid)}. Will use it`); + clearInterval(poll); + resolve(found); + } + } else if (simsOnly.length > 0) { + logSuccess(`Found active emulator! ${chalk().white(simsOnly[0].udid)}. Will use it`); clearInterval(poll); - resolve(v[0]); + resolve(simsOnly[0]); } else { logRaw(`looking for active emulators: attempt ${attempts}/${maxAttempts}`); attempts++; diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index b97df12b3a..3f289cc65d 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -117,7 +117,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { if (dev) return dev; await launchAndroidSimulator(c, response.chosenEmulator, true); - const device = await checkForActiveEmulator(c); + const device = await checkForActiveEmulator(c, response.chosenEmulator); return device; } } else { @@ -139,7 +139,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { return foundDevice; } await launchAndroidSimulator(c, foundDevice, true); - const device = await checkForActiveEmulator(c); + const device = await checkForActiveEmulator(c, foundDevice.name); return device; } logDebug('Target not found, asking where to run'); @@ -156,7 +156,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { return askWhereToRun(); } else if (!foundDevice.isActive) { await launchAndroidSimulator(c, foundDevice, true); - const device = await checkForActiveEmulator(c); + const device = await checkForActiveEmulator(c, foundDevice.name); return device; } return foundDevice; From ac42ac04e47ed15968edac7c064c7ba851146f61 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Wed, 6 Dec 2023 17:32:38 +0100 Subject: [PATCH 13/13] linting --- packages/sdk-android/src/runner.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 3f289cc65d..3d7279b73d 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -98,7 +98,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { if (activeDevices.length || inactiveDevices.length) { // No device active and device param is passed, exiting if (c.program.device && !activeDevices.length) { - return logError('No active devices found, please connect one or remove the device argument', true) + return logError('No active devices found, please connect one or remove the device argument', true); } const activeString = composeDevicesArray(activeDevices); @@ -136,8 +136,8 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { const foundDevice = devicesAndEmulators.find((d) => d.udid.includes(target) || d.name.includes(target)); if (foundDevice) { if (foundDevice.isActive) { - return foundDevice; - } + return foundDevice; + } await launchAndroidSimulator(c, foundDevice, true); const device = await checkForActiveEmulator(c, foundDevice.name); return device; @@ -165,7 +165,7 @@ export const getAndroidDeviceToRunOn = async (c: Context) => { logDebug('Target not provided, asking where to run'); return askWhereToRun(); } -} +}; export const runAndroid = async (c: Context, device: AndroidDevice) => { logTask('runAndroid', `target:${device.udid}`);