From 06aaaf288dddaa9f73ff03e8c329eca98e17f2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Fri, 19 Jan 2024 17:10:10 +0100 Subject: [PATCH] fix: launching activity defined with fully qualified name --- .../__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('.');