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

fix: correct derivation of fully specified android launch activities #2388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikehardy
Copy link
Contributor

@mikehardy mikehardy commented May 10, 2024

Summary:

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"

So basically I added an "or" in the first conditional chunk that just uses the mainActivity as-is, that will allow that if (!mainActivity.startsWith('.') && mainActivity.includes('.')) which I think captures the spirit of the previous code in this spot that was trying to build the component name

Test Plan:

I added a test case for the failure - when I run yarn test before it fails only that test, and after, they all pass

I ran my app with the built tryLaunchAppOnDevice.js file before and after the fix, it failed before the fix, it worked after the fix

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

@mikehardy mikehardy requested a review from cortinico as a code owner May 10, 2024 22:09
@mikehardy mikehardy added platform: android javascript Pull requests that update Javascript code and removed bugfix labels May 10, 2024
@cortinico
Copy link
Member

Then adding this as a test case would be great

We really need tests for those functions :(

@mikehardy
Copy link
Contributor Author

@cortinico what's a way to run just a single jest test? if the test/debug loop was quick I'd add a new AndroidManifest (or a run with a --main-activity specified) that matches my case and fails-without-patch / works-with-patch

There are tests actually - for most of the cases I think. Just not this one which allowed the regression to slip in

@cortinico
Copy link
Member

@cortinico what's a way to run just a single jest test?

You can use jest -t <...>. Docs are here https://jestjs.io/docs/cli#--testnamepatternregex

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"
@mikehardy mikehardy force-pushed the fix-fully-specified-non-package-android-main-activity branch from b5e0f56 to dc3ce6a Compare May 11, 2024 15:49
@mikehardy
Copy link
Contributor Author

@cortinico Got it!
Wrote a new test, re-pushed the branch with it .
Here's the test before my patch, it mirrors the regression I saw in it's failure:

image

Passes with my patch. No other tests fail with or without my patch so hopefully I haven't regressed something else...

mike@isabela:~/work/react-random/cli (fix-fully-specified-non-package-android-main-activity *) % yarn jest --testMatch "**/cli-platform-android/**/__tests__/*tryLaunchAppOnDevice*.test.ts"
yarn run v1.22.22
$ /Users/mike/work/react-random/cli/node_modules/.bin/jest --testMatch '**/cli-platform-android/**/__tests__/*tryLaunchAppOnDevice*.test.ts'
 PASS   unit  packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts
 PASS   e2e  packages/cli-platform-android/src/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts
  ● Console

    console.log
      info Starting the app on "emulator-5554"...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app on "emulator-5554"...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app on "emulator-5554"...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app on "emulator-5554"...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)

    console.log
      info Starting the app...

      at Object.info (packages/cli-tools/src/logger.ts:20:13)


Test Suites: 2 passed, 2 total
Tests:       14 passed, 14 total
Snapshots:   0 total
Time:        0.747 s, estimated 1 s
Ran all test suites in 2 projects.
✨  Done in 1.79s.
mike@isabela:~/work/react-random/cli (fix-fully-specified-non-package-android-main-activity *) % 

@mikehardy
Copy link
Contributor Author

Persistent windows-2019 node20 CI test failure appears unrelated

Sat, 11 May 2024 16:03:51 GMT
warning @react-native-community/cli@14.0.0-alpha.5: Invalid bin entry for "@react-native-community/cli" (in "@react-native-community/cli").
Sat, 11 May 2024 16:03:52 GMT
[1/4] Resolving packages...
Sat, 11 May 2024 [16](https://github.com/react-native-community/cli/actions/runs/9044794126/job/24853954107?pr=2388#step:10:17):03:52 GMT
[2/4] Fetching packages...
Sat, 11 May 2024 16:06:10 GMT
info There appears to be trouble with your network connection. Retrying...
Sat, 11 May 2024 16:06:10 GMT
warning @react-native-community/cli@14.0.0-alpha.5: Invalid bin entry for "@react-native-community/cli" (in "@react-native-community/cli").
Sat, 11 May 2024 16:06:50 GMT
[3/4] Linking dependencies...
Sat, 11 May 2024 16:07:07 GMT
[4/4] Building fresh packages...
Sat, 11 May [20](https://github.com/react-native-community/cli/actions/runs/9044794126/job/24853954107?pr=2388#step:10:21)24 16:07:08 GMT
error D:\a\cli\cli\node_modules\deasync: Command failed.
Sat, 11 May 2024 16:07:08 GMT
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Sat, 11 May 2024 16:07:08 GMT
Exit code: 1
Sat, 11 May 2024 16:07:08 GMT
Command: node ./build.js

@mikehardy
Copy link
Contributor Author

@cortinico just a gentle ping on this, as the change is small (so maybe a satisfying review!) and I've backed it by a test now :-)

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix javascript Pull requests that update Javascript code platform: android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants