Skip to content

Commit a00f927

Browse files
mikehardythymikee
authored andcommitted
fix: correct derivation of fully specified android launch activities (#2388)
If you have a main activity that is not in package, and is fully specified, it used to work, but it regressed after adding auto-activity detection If your launcher / `MAIN` activity either specified by --main-activity or in AndroidManifest.xml is fully specified for example like "com.zoontek.rnbootsplash.RNBootSplashActivity" then it needs to launch for example "com.kullki.kscore.dev/com.zoontek.rnbootsplash.RNBootSplashActivity" not "com.kullki.kscore.dev/com.kullki.kscore.dev.com.zoontek.rnbootsplash.RNBootSplashActivity"
1 parent f0109b7 commit a00f927

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,34 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with diffe
118118
);
119119
});
120120

121+
test('launches adb shell with intent to launch fully specified activity with different appId than packageName and an app suffix on a device', () => {
122+
tryLaunchAppOnDevice(
123+
device,
124+
{
125+
...androidProject,
126+
mainActivity: 'com.zoontek.rnbootsplash.RNBootSplashActivity',
127+
},
128+
adbPath,
129+
{
130+
...args,
131+
appIdSuffix: 'dev',
132+
},
133+
);
134+
135+
expect(execa.sync).toHaveBeenCalledWith(
136+
'path/to/adb',
137+
[
138+
'-s',
139+
'emulator-5554',
140+
...shellStartCommand,
141+
'-n',
142+
'com.myapp.custom.dev/com.zoontek.rnbootsplash.RNBootSplashActivity',
143+
...actionCategoryFlags,
144+
],
145+
{stdio: 'inherit'},
146+
);
147+
});
148+
121149
test('--appId flag overwrites applicationId setting in androidProject', () => {
122150
tryLaunchAppOnDevice(undefined, androidProject, adbPath, {
123151
...args,

packages/cli-platform-android/src/commands/runAndroid/tryLaunchAppOnDevice.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ function tryLaunchAppOnDevice(
2424
.filter(Boolean)
2525
.join('.');
2626

27-
const activityToLaunch = mainActivity.startsWith(packageName)
28-
? mainActivity
29-
: mainActivity.startsWith('.')
30-
? [packageName, mainActivity].join('')
31-
: [packageName, mainActivity].filter(Boolean).join('.');
27+
const activityToLaunch =
28+
mainActivity.startsWith(packageName) ||
29+
(!mainActivity.startsWith('.') && mainActivity.includes('.'))
30+
? mainActivity
31+
: mainActivity.startsWith('.')
32+
? [packageName, mainActivity].join('')
33+
: [packageName, mainActivity].filter(Boolean).join('.');
3234

3335
try {
3436
// Here we're using the same flags as Android Studio to launch the app

0 commit comments

Comments
 (0)