Skip to content

Android: honor a port in the metro.host system property - #58585

Open
janicduplessis wants to merge 1 commit into
react:mainfrom
janicduplessis:@janic/android-metro-host-port
Open

janicduplessis wants to merge 1 commit into
react:mainfrom
janicduplessis:@janic/android-metro-host-port

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary:

On Android the metro.host system property overrides the dev server host, but the port is always the compiled react_native_dev_server_port resource. So there is no way to point an installed app at a Metro on another port from outside the app: the only runtime override is debug_http_host in the app's SharedPreferences, which is set from the dev menu, or by rewriting the prefs XML through run-as on a debuggable build. iOS has this covered: RCTBundleURLProvider takes RCT_jsLocation from user defaults and, when the value contains a colon, uses it verbatim as host:port (serverRootWithHostPort).

This makes metro.host behave the same way: a value containing a colon is returned as-is, otherwise the compiled port is appended as before. adb shell setprop metro.host 10.0.2.2:8083 then does on an emulator what defaults write <bundleId> RCT_jsLocation localhost:8083 does on a simulator.

The case where this matters is several checkouts of one app, each with its own Metro port (git worktrees, parallel agents), sharing one build: the app is compiled once with port 8081 and pointed at the right port at launch. That already works on iOS; Android needed the prefs rewrite.

An IPv6 literal in metro.host also contains colons, but that was already broken (::1:8081 is not a valid authority; it would need brackets), so no working configuration changes.

Changelog:

[ANDROID] [ADDED] - metro.host accepts a host:port value, matching RCT_jsLocation on iOS

Test Plan:

yarn format-check-kotlin passes.

RNTester built from this branch (:packages:rn-tester:android:app:assembleDebug), installed on an API 34 google_apis arm64 emulator (adb root is needed to set the property; a Play image refuses setprop, which is a pre-existing limitation of metro.host). Metro started with react-native start --port 8099; nothing listening on 8081.

metro.host result
10.0.2.2:8099 app loads; Metro on 8099 logs BUNDLE js/RNTesterApp.android.js
10.0.2.2 unchanged: compiled port appended, app tries 10.0.2.2:8081 and fails to connect

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 18, 2026
@facebook-github-tools facebook-github-tools Bot added the Contributor A React Native contributor. label Sep 18, 2026
@janicduplessis
janicduplessis marked this pull request as ready for review September 18, 2026 04:06
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 18, 2026
metro.host could override the dev server host, but the port always came
from the compiled react_native_dev_server_port resource. Accept a
"host:port" value verbatim, the way RCTBundleURLProvider on iOS treats a
RCT_jsLocation value that carries a port, so a device can be pointed at a
Metro on a non-default port without rebuilding the app or rewriting its
SharedPreferences.
@janicduplessis
janicduplessis force-pushed the @janic/android-metro-host-port branch from 3c67a6f to 1075bbb Compare September 18, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Contributor A React Native contributor. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant