From c61cb4a73dfc03c09dcf0522ce1f5de46e5e2212 Mon Sep 17 00:00:00 2001 From: ElenaDiachenko Date: Thu, 24 Oct 2024 16:32:57 +0300 Subject: [PATCH 1/4] fix android --- packages/sdk-android/src/runner.ts | 14 ++++- packages/sdk-android/src/taskOptions.ts | 4 ++ packages/sdk-android/src/tasks/taskRun.ts | 1 + .../sdk-react-native/src/androidRunner.ts | 57 ++++++++++++++----- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index 475f01494..cac7f5926 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -29,6 +29,7 @@ import { RnvPlatform, logInfo, RnvPlatformKey, + execCLI, } from '@rnv/core'; import { parseAndroidManifestSync } from './manifestParser'; import { @@ -186,7 +187,18 @@ export const getAndroidDeviceToRunOn = async () => { export const runAndroid = async (device: AndroidDevice) => { logDefault('runAndroid', `target:${device.udid}`); - + const c = getContext(); + const { uninstall } = c.program.opts(); + if (uninstall) { + const packageId = getConfigProp('id'); + if (packageId) { + try { + await execCLI(CLI_ANDROID_ADB, `uninstall ${packageId}`, { silent: true }); + } catch (e) { + logWarning(`Failed to uninstall ${packageId}`); + } + } + } await runReactNativeAndroid(device); }; diff --git a/packages/sdk-android/src/taskOptions.ts b/packages/sdk-android/src/taskOptions.ts index c0b760765..078619e58 100644 --- a/packages/sdk-android/src/taskOptions.ts +++ b/packages/sdk-android/src/taskOptions.ts @@ -18,4 +18,8 @@ export const TaskOptions = createTaskOptionsMap([ altKey: 'resetAdb', description: 'Forces to reset android adb', }, + { + key: 'uninstall', + description: 'Uninstall the app with the current id', + }, ]); diff --git a/packages/sdk-android/src/tasks/taskRun.ts b/packages/sdk-android/src/tasks/taskRun.ts index e3f8c2968..dda342ced 100644 --- a/packages/sdk-android/src/tasks/taskRun.ts +++ b/packages/sdk-android/src/tasks/taskRun.ts @@ -34,6 +34,7 @@ export default createTask({ ...RnvTaskOptionPresets.withRun(), TaskOptions.resetAdb, TaskOptions.skipTargetCheck, + TaskOptions.uninstall, ], platforms: SdkPlatforms, }); diff --git a/packages/sdk-react-native/src/androidRunner.ts b/packages/sdk-react-native/src/androidRunner.ts index f73c0ddb6..f9027936c 100644 --- a/packages/sdk-react-native/src/androidRunner.ts +++ b/packages/sdk-react-native/src/androidRunner.ts @@ -12,6 +12,9 @@ import { CoreEnvVars, ExecOptionsPresets, getContext, + execCLI, + logWarning, + inquirerPrompt, } from '@rnv/core'; import { EnvVars } from './env'; import { getEntryFile } from '@rnv/sdk-utils'; @@ -95,20 +98,48 @@ export const runReactNativeAndroid = async (device: { udid?: string } | undefine if (udid) { command += ` --deviceId=${udid}`; } + const executeCommand = async () => { + return executeAsync(command, { + env: { + ...CoreEnvVars.BASE(), + ...CoreEnvVars.RNV_EXTENSIONS(), + ...EnvVars.RCT_METRO_PORT(), + ...EnvVars.RNV_REACT_NATIVE_PATH(), + ...EnvVars.RNV_APP_ID(), + ...EnvVars.RNV_SKIP_LINKING(), + }, + cwd: appFolder, + // To display react-native CLI logs in RNV executed terminal + ...ExecOptionsPresets.INHERIT_OUTPUT_NO_SPINNER, + }); + }; - return executeAsync(command, { - env: { - ...CoreEnvVars.BASE(), - ...CoreEnvVars.RNV_EXTENSIONS(), - ...EnvVars.RCT_METRO_PORT(), - ...EnvVars.RNV_REACT_NATIVE_PATH(), - ...EnvVars.RNV_APP_ID(), - ...EnvVars.RNV_SKIP_LINKING(), - }, - cwd: appFolder, - //This is required to make rn cli logs visible in rnv executed terminal - ...ExecOptionsPresets.INHERIT_OUTPUT_NO_SPINNER, - }); + try { + return await executeCommand(); + } catch (error) { + const packageId = getConfigProp('id'); + if (packageId) { + const { confirm } = await inquirerPrompt({ + name: 'confirm', + type: 'confirm', + message: `Failed to build the app. Try to uninstall and retry?`, + }); + + if (confirm) { + try { + await execCLI('androidAdb', `uninstall ${packageId}`, { silent: true }); + } catch (e) { + logWarning(`Failed to uninstall ${packageId}`); + } + + return await executeCommand(); + } else { + return Promise.reject(error); + } + } else { + return Promise.reject(error); + } + } }; export const buildReactNativeAndroid = async () => { From 3a85c7ca56c01f26c2ffb4b1b43986452fca5177 Mon Sep 17 00:00:00 2001 From: ElenaDiachenko Date: Fri, 25 Oct 2024 14:16:50 +0300 Subject: [PATCH 2/4] fix ios --- packages/sdk-apple/src/runner.ts | 28 +++++++++++++++++-- packages/sdk-apple/src/taskOptions.ts | 4 +++ packages/sdk-apple/src/tasks/taskRun.ts | 1 + .../sdk-react-native/src/androidRunner.ts | 12 ++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/sdk-apple/src/runner.ts b/packages/sdk-apple/src/runner.ts index 9788fa626..bbb4ce2e7 100644 --- a/packages/sdk-apple/src/runner.ts +++ b/packages/sdk-apple/src/runner.ts @@ -102,9 +102,10 @@ export const getIosDeviceToRunOn = async (c: Context) => { )} udid: ${chalk().bold.white(devicesArr[0].udid)}` ); if (devicesArr[0].udid) { - p = `--udid ${devicesArr[0].udid}`; c.runtime.targetUDID = devicesArr[0].udid; + p = `--udid ${devicesArr[0].udid}`; } else { + c.runtime.targetUDID = devicesArr[0].udid; p = `--device ${devicesArr[0].name}`; } } else if (availableDevices.length) { @@ -152,6 +153,7 @@ export const getIosDeviceToRunOn = async (c: Context) => { }); if (!chosenTarget.isDevice) { c.runtime.target = chosenTarget.name; + c.runtime.targetUDID = chosenTarget.udid; if (c.runtime.target) { p = `--simulator ${c.runtime.target.replace(/(\s+)/g, '\\$1')}`; } @@ -193,7 +195,7 @@ export const getIosDeviceToRunOn = async (c: Context) => { }); c.runtime.target = currentTarget.name; - + c.runtime.targetUDID = currentTarget.udid; if (chosenAction === actionLocalUpdate || (chosenAction === actionGlobalUpdate && localOverridden)) { const configLocal = c.files.project.configLocal || {}; if (!configLocal.defaultTargets) configLocal.defaultTargets = {}; @@ -216,7 +218,7 @@ export const getIosDeviceToRunOn = async (c: Context) => { } if (!desiredSim?.isDevice) { const target = c.runtime.target?.replace(/(\s+)/g, '\\$1'); - + c.runtime.targetUDID = desiredSim?.udid; p = `--simulator ${target}`; } else { return run(desiredSim); @@ -273,11 +275,31 @@ export const runXcodeProject = async (runDeviceArguments?: string) => { const runScheme = getConfigProp('runScheme') || 'Debug'; const bundleIsDev = getConfigProp('bundleIsDev') === true; const bundleAssets = getConfigProp('bundleAssets') === true; + const { uninstall } = c.program.opts(); if (runDeviceArguments) { // await launchAppleSimulator(c, c.runtime.target); @TODO - do we still need this? RN CLI does it as well //const allowProvisioningUpdates = getConfigProp('allowProvisioningUpdates', true); //if (allowProvisioningUpdates) p = `${p} --allowProvisioningUpdates`; + if (uninstall) { + const packageId = getConfigProp('id'); + if (packageId) { + try { + if (runDeviceArguments.includes('simulator')) { + await executeAsync(`xcrun simctl uninstall ${c.runtime.targetUDID} ${packageId}`); + } else { + console.log(`xcrun devicectl device uninstall app -d ${c.runtime.targetUDID} ${packageId}`); + await executeAsync( + `xcrun devicectl device uninstall app -d ${c.runtime.targetUDID} ${packageId}` + ); + } + } catch (e) { + console.log(e); + logWarning(`Failed to uninstall ${packageId}`); + } + } + } + if (bundleAssets) { await packageReactNativeIOS(bundleIsDev); } diff --git a/packages/sdk-apple/src/taskOptions.ts b/packages/sdk-apple/src/taskOptions.ts index b500e0eb7..ef4d11f56 100644 --- a/packages/sdk-apple/src/taskOptions.ts +++ b/packages/sdk-apple/src/taskOptions.ts @@ -67,6 +67,10 @@ export const TaskOptions = createTaskOptionsMap([ isRequired: true, description: 'Filter value', }, + { + key: 'uninstall', + description: 'Uninstall the app with the current id', + }, ]); export const TaskOptionPresets = createTaskOptionsPreset({ diff --git a/packages/sdk-apple/src/tasks/taskRun.ts b/packages/sdk-apple/src/tasks/taskRun.ts index bc3b2619a..32eefe9de 100644 --- a/packages/sdk-apple/src/tasks/taskRun.ts +++ b/packages/sdk-apple/src/tasks/taskRun.ts @@ -28,6 +28,7 @@ export default createTask({ ...RnvTaskOptionPresets.withConfigure(), ...RnvTaskOptionPresets.withRun(), TaskOptions.skipTargetCheck, + TaskOptions.uninstall, ...TaskOptionPresets.withConfigure(), ], platforms: SdkPlatforms, diff --git a/packages/sdk-react-native/src/androidRunner.ts b/packages/sdk-react-native/src/androidRunner.ts index f9027936c..2794897f7 100644 --- a/packages/sdk-react-native/src/androidRunner.ts +++ b/packages/sdk-react-native/src/androidRunner.ts @@ -134,10 +134,18 @@ export const runReactNativeAndroid = async (device: { udid?: string } | undefine return await executeCommand(); } else { - return Promise.reject(error); + if (typeof error === 'string') { + return Promise.reject(error); + } else if (error instanceof Error) { + return Promise.reject(error.message); + } } } else { - return Promise.reject(error); + if (typeof error === 'string') { + return Promise.reject(error); + } else if (error instanceof Error) { + return Promise.reject(error.message); + } } } }; From 61b9dd9c3a1884edd71b15ec588c657cc73266e4 Mon Sep 17 00:00:00 2001 From: ElenaDiachenko Date: Mon, 28 Oct 2024 09:24:42 +0200 Subject: [PATCH 3/4] remove unnecessary func --- packages/sdk-apple/src/runner.ts | 28 +++---------------------- packages/sdk-apple/src/taskOptions.ts | 4 ---- packages/sdk-apple/src/tasks/taskRun.ts | 1 - 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/packages/sdk-apple/src/runner.ts b/packages/sdk-apple/src/runner.ts index bbb4ce2e7..9788fa626 100644 --- a/packages/sdk-apple/src/runner.ts +++ b/packages/sdk-apple/src/runner.ts @@ -102,10 +102,9 @@ export const getIosDeviceToRunOn = async (c: Context) => { )} udid: ${chalk().bold.white(devicesArr[0].udid)}` ); if (devicesArr[0].udid) { - c.runtime.targetUDID = devicesArr[0].udid; p = `--udid ${devicesArr[0].udid}`; - } else { c.runtime.targetUDID = devicesArr[0].udid; + } else { p = `--device ${devicesArr[0].name}`; } } else if (availableDevices.length) { @@ -153,7 +152,6 @@ export const getIosDeviceToRunOn = async (c: Context) => { }); if (!chosenTarget.isDevice) { c.runtime.target = chosenTarget.name; - c.runtime.targetUDID = chosenTarget.udid; if (c.runtime.target) { p = `--simulator ${c.runtime.target.replace(/(\s+)/g, '\\$1')}`; } @@ -195,7 +193,7 @@ export const getIosDeviceToRunOn = async (c: Context) => { }); c.runtime.target = currentTarget.name; - c.runtime.targetUDID = currentTarget.udid; + if (chosenAction === actionLocalUpdate || (chosenAction === actionGlobalUpdate && localOverridden)) { const configLocal = c.files.project.configLocal || {}; if (!configLocal.defaultTargets) configLocal.defaultTargets = {}; @@ -218,7 +216,7 @@ export const getIosDeviceToRunOn = async (c: Context) => { } if (!desiredSim?.isDevice) { const target = c.runtime.target?.replace(/(\s+)/g, '\\$1'); - c.runtime.targetUDID = desiredSim?.udid; + p = `--simulator ${target}`; } else { return run(desiredSim); @@ -275,31 +273,11 @@ export const runXcodeProject = async (runDeviceArguments?: string) => { const runScheme = getConfigProp('runScheme') || 'Debug'; const bundleIsDev = getConfigProp('bundleIsDev') === true; const bundleAssets = getConfigProp('bundleAssets') === true; - const { uninstall } = c.program.opts(); if (runDeviceArguments) { // await launchAppleSimulator(c, c.runtime.target); @TODO - do we still need this? RN CLI does it as well //const allowProvisioningUpdates = getConfigProp('allowProvisioningUpdates', true); //if (allowProvisioningUpdates) p = `${p} --allowProvisioningUpdates`; - if (uninstall) { - const packageId = getConfigProp('id'); - if (packageId) { - try { - if (runDeviceArguments.includes('simulator')) { - await executeAsync(`xcrun simctl uninstall ${c.runtime.targetUDID} ${packageId}`); - } else { - console.log(`xcrun devicectl device uninstall app -d ${c.runtime.targetUDID} ${packageId}`); - await executeAsync( - `xcrun devicectl device uninstall app -d ${c.runtime.targetUDID} ${packageId}` - ); - } - } catch (e) { - console.log(e); - logWarning(`Failed to uninstall ${packageId}`); - } - } - } - if (bundleAssets) { await packageReactNativeIOS(bundleIsDev); } diff --git a/packages/sdk-apple/src/taskOptions.ts b/packages/sdk-apple/src/taskOptions.ts index ef4d11f56..b500e0eb7 100644 --- a/packages/sdk-apple/src/taskOptions.ts +++ b/packages/sdk-apple/src/taskOptions.ts @@ -67,10 +67,6 @@ export const TaskOptions = createTaskOptionsMap([ isRequired: true, description: 'Filter value', }, - { - key: 'uninstall', - description: 'Uninstall the app with the current id', - }, ]); export const TaskOptionPresets = createTaskOptionsPreset({ diff --git a/packages/sdk-apple/src/tasks/taskRun.ts b/packages/sdk-apple/src/tasks/taskRun.ts index 32eefe9de..bc3b2619a 100644 --- a/packages/sdk-apple/src/tasks/taskRun.ts +++ b/packages/sdk-apple/src/tasks/taskRun.ts @@ -28,7 +28,6 @@ export default createTask({ ...RnvTaskOptionPresets.withConfigure(), ...RnvTaskOptionPresets.withRun(), TaskOptions.skipTargetCheck, - TaskOptions.uninstall, ...TaskOptionPresets.withConfigure(), ], platforms: SdkPlatforms, From 5f15c317a082af3758a0f382db6df48bd55b2cef Mon Sep 17 00:00:00 2001 From: ElenaDiachenko Date: Sun, 3 Nov 2024 16:08:06 +0200 Subject: [PATCH 4/4] fix error handling --- packages/sdk-android/src/runner.ts | 2 +- packages/sdk-react-native/src/androidRunner.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sdk-android/src/runner.ts b/packages/sdk-android/src/runner.ts index cac7f5926..386527fec 100644 --- a/packages/sdk-android/src/runner.ts +++ b/packages/sdk-android/src/runner.ts @@ -195,7 +195,7 @@ export const runAndroid = async (device: AndroidDevice) => { try { await execCLI(CLI_ANDROID_ADB, `uninstall ${packageId}`, { silent: true }); } catch (e) { - logWarning(`Failed to uninstall ${packageId}`); + return Promise.reject(`Failed to uninstall ${packageId}`); } } } diff --git a/packages/sdk-react-native/src/androidRunner.ts b/packages/sdk-react-native/src/androidRunner.ts index 2794897f7..69bf29783 100644 --- a/packages/sdk-react-native/src/androidRunner.ts +++ b/packages/sdk-react-native/src/androidRunner.ts @@ -129,7 +129,7 @@ export const runReactNativeAndroid = async (device: { udid?: string } | undefine try { await execCLI('androidAdb', `uninstall ${packageId}`, { silent: true }); } catch (e) { - logWarning(`Failed to uninstall ${packageId}`); + return Promise.reject(`Failed to uninstall ${packageId}`); } return await executeCommand();