Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify codepath for retrieveing metro location on Android (#42617)
Summary: With the current ways metro location is determined, when we want to use a different metro port this requires app to be rebuild as the port and location are stored in resource file that gets compiled to R.class. The only way to avoid app rebuild due to a port change is to use shared preferences that can be accessed from dev menu, where metro URL can be specified. However, due to a separate code-paths for retrieving bundle location and for `/inspector/device` calls, the setting only applies to the former. As a consequence, you can change metro URL in the shared preferences, but debugging would only work if you use the default port or you rebuild the app with the correct port number. This PR removes the separate code-path for retrieving inspector URL including all the dependencies scattered across different files including the gradle plugin. We then replace calls to `PackagerConnectionSettings.getInspectorServerHost` with `PackagerConnectionSettings.getDebugServerHost` which respects the shared preferences and other possible ways of configuring the port. I decided to remove the separate inspector URL code path, as the resource value for inspector port added in #23616 was never functioning properly due to a bug. In the said PR introduced a bug in [AndroidInfoHelpers.java](https://github.com/facebook/react-native/blob/a13d51ff1c38ea85e59f4215563c0dd05452f670/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.java#L77) where `react_native_dev_server_port` was used instead `react_native_inspector_proxy_port`. As a result the added resource value was never read. This can be potentially a breaking change as I'm removing some public methods. However I think it is unlikely anyone relied on said methods. As a part of this PR I'm also changing occurences of removed methods from ReactAndroid.api – I don't know how to test those changes since I don't understand how this file is used as it doesn't have any references in public code. ## Changelog: [ANDROID] [FIXED] - Make Android respect metro location from shared preferences for the debugger workflow Pull Request resolved: #42617 Test Plan: 1. Run android app on emulator using default port 2. Check the debugger works when using "Open Debugger" option from dev menu 3. Restart metro with custom port (`--port 9090`) while keeping the app running 4. Open dev menu, click "Settings" then "Debug server host & port", put "10.0.2.2:9090" there 5. Reload the app 6. Before this change things like hot reload would continue to work while "Open Debugger" option would do nothing 7. After this change both reloading and debugging will work Important: I haven't tested changes made to ReactAndroid.api as I don't know what this files is used for with no references in the codebase. Reviewed By: cortinico Differential Revision: D53010023 Pulled By: huntie fbshipit-source-id: cc8b9c5c7e834ec9ea02b1ed5acf94f04f7b7116
- Loading branch information