From da7b6ac7266f8ab3cc67170101d0b6f61bfa6e5e Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:59:21 +0100 Subject: [PATCH] fix: launching activity defined with fully qualified name (#2269) (#2283) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Pierzchała --- .../__tests__/tryLaunchAppOnDevice.test.ts | 22 +++++++++++++++++++ .../runAndroid/tryLaunchAppOnDevice.ts | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts b/packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts index 39630bcdf..4520d4bd7 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts @@ -59,6 +59,28 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with diffe ); }); +test('launches adb shell with intent to launch com.myapp.MainActivity with different appId than packageName on a simulator when mainActivity is fully qualified name', () => { + tryLaunchAppOnDevice( + device, + {...androidProject, mainActivity: 'com.myapp.MainActivity'}, + adbPath, + args, + ); + + expect(execa.sync).toHaveBeenCalledWith( + 'path/to/adb', + [ + '-s', + 'emulator-5554', + ...shellStartCommand, + '-n', + 'com.myapp.custom/com.myapp.MainActivity', + ...actionCategoryFlags, + ], + {stdio: 'inherit'}, + ); +}); + test('launches adb shell with intent to launch com.myapp.MainActivity with same appId as packageName on a simulator', () => { tryLaunchAppOnDevice( device, diff --git a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchAppOnDevice.ts b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchAppOnDevice.ts index 2a0dda4a0..cd9241353 100644 --- a/packages/cli-platform-android/src/commands/runAndroid/tryLaunchAppOnDevice.ts +++ b/packages/cli-platform-android/src/commands/runAndroid/tryLaunchAppOnDevice.ts @@ -24,7 +24,9 @@ function tryLaunchAppOnDevice( .filter(Boolean) .join('.'); - const activityToLaunch = mainActivity.includes('.') + const activityToLaunch = mainActivity.startsWith(packageName) + ? mainActivity + : mainActivity.startsWith('.') ? [packageName, mainActivity].join('') : [packageName, mainActivity].filter(Boolean).join('.');