Skip to content

Commit

Permalink
fix: correct derivation of fully specified android launch activities (#…
Browse files Browse the repository at this point in the history
…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"
  • Loading branch information
mikehardy authored and thymikee committed Jun 5, 2024
1 parent f0109b7 commit a00f927
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,34 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with diffe
);
});

test('launches adb shell with intent to launch fully specified activity with different appId than packageName and an app suffix on a device', () => {
tryLaunchAppOnDevice(
device,
{
...androidProject,
mainActivity: 'com.zoontek.rnbootsplash.RNBootSplashActivity',
},
adbPath,
{
...args,
appIdSuffix: 'dev',
},
);

expect(execa.sync).toHaveBeenCalledWith(
'path/to/adb',
[
'-s',
'emulator-5554',
...shellStartCommand,
'-n',
'com.myapp.custom.dev/com.zoontek.rnbootsplash.RNBootSplashActivity',
...actionCategoryFlags,
],
{stdio: 'inherit'},
);
});

test('--appId flag overwrites applicationId setting in androidProject', () => {
tryLaunchAppOnDevice(undefined, androidProject, adbPath, {
...args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ function tryLaunchAppOnDevice(
.filter(Boolean)
.join('.');

const activityToLaunch = mainActivity.startsWith(packageName)
? mainActivity
: mainActivity.startsWith('.')
? [packageName, mainActivity].join('')
: [packageName, mainActivity].filter(Boolean).join('.');
const activityToLaunch =
mainActivity.startsWith(packageName) ||
(!mainActivity.startsWith('.') && mainActivity.includes('.'))
? mainActivity
: mainActivity.startsWith('.')
? [packageName, mainActivity].join('')
: [packageName, mainActivity].filter(Boolean).join('.');

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

0 comments on commit a00f927

Please sign in to comment.