Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--run-android with --main-activity class not in main package not possible #1212

Closed
mikehardy opened this issue Jul 1, 2020 · 5 comments
Closed

Comments

@mikehardy
Copy link
Contributor

Environment

Description

Hi there!

If you have a launch activity with a fully-qualified class name that is not in your main application package, it is not possible to use the CLI to launch it, as the main application package is pre-pended to the specified main activity even if the activity is fully qualified

`${packageNameWithSuffix}/${packageName}.${args.mainActivity}`,

I believe the correct thing to do is to check of the --main-activity begins with a . character or not, and only pretend the package name if it begins with a period

Note: you cannot just send the activity in without pre-pending package name to it otherwise it does not work with build flavors

Another possibility is to ask the Android "monkey" to simulate an icon click so the default launcher resolves the launcher activity for you: https://stackoverflow.com/a/29931521/9910298

adb shell monkey -p app.package.name -c android.intent.category.LAUNCHER 1

Either would work.

Would you guys like a PR? If so, which direction?

Reproducible Demo

This comes up with the react-native-bootsplash package - there is no way to start the launcher activity so the dev experience does not actually simulate what release will feel like:

https://github.com/zoontek/react-native-bootsplash/blob/db874a022c97d981c211b2a92a3104d6a5d42c0a/example/android/app/src/main/AndroidManifest.xml#L23

@mikehardy
Copy link
Contributor Author

The monkey style works for me on Android 4.4 real device and android 9 emulator, for what it's worth:

mike@isabela:~/work/Kullki/ksocialscore/packages/public-app (rebranding *) % more patches/@react-native-community+cli-platform-android+4.10.1.patch 
diff --git a/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/tryLaunchAppOnDevice.js b/node_modules/@react-native-community/cli-platform-android/build/co
mmands/runAndroid/tryLaunchAppOnDevice.js
index 63783ce..d2ed804 100644
--- a/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/tryLaunchAppOnDevice.js
+++ b/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/tryLaunchAppOnDevice.js
@@ -42,7 +42,7 @@ function tryLaunchAppOnDevice(device, packageName, adbPath, args) {
   const packageNameWithSuffix = [appId || packageName, appIdSuffix].filter(Boolean).join('.');
 
   try {
-    const adbArgs = ['shell', 'am', 'start', '-n', `${packageNameWithSuffix}/${packageName}.${args.mainActivity}`];
+    const adbArgs = ['shell', 'monkey', '-p', `${packageNameWithSuffix}`, '-c', 'android.intent.category.LAUNCHER', '1'];
 
     if (device) {
       adbArgs.unshift('-s', device);

@mikehardy
Copy link
Contributor Author

@zoontek you might be interested in this, it affects the dev experience on react-native-bootsplash in that the react-native CLI doesn't launch the app the same way the android launcher does, so developers may not realize it but they aren't seeing what the release bootsplash experience will be in their usual dev launches

@zoontek
Copy link
Member

zoontek commented Jul 1, 2020

@mikehardy I will remove the need for SplashActivity in the next major version, it will not be an issue anymore 🙂

@mikehardy
Copy link
Contributor Author

good to hear @zoontek - I still really like the change to "monkey" style launch here though as it delegates the launch activity resolution to the system

@mikehardy
Copy link
Contributor Author

This was fixed in #1242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants