Android: honor a port in the metro.host system property - #58585
Open
janicduplessis wants to merge 1 commit into
Open
janicduplessis wants to merge 1 commit into
janicduplessis wants to merge 1 commit into
Conversation
janicduplessis
marked this pull request as ready for review
September 18, 2026 04:06
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
force-pushed
the
@janic/android-metro-host-port
branch
from
September 18, 2026 14:52
3c67a6f to
1075bbb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
On Android the
metro.hostsystem property overrides the dev server host, but the port is always the compiledreact_native_dev_server_portresource. So there is no way to point an installed app at a Metro on another port from outside the app: the only runtime override isdebug_http_hostin the app's SharedPreferences, which is set from the dev menu, or by rewriting the prefs XML throughrun-ason a debuggable build. iOS has this covered:RCTBundleURLProvidertakesRCT_jsLocationfrom user defaults and, when the value contains a colon, uses it verbatim ashost:port(serverRootWithHostPort).This makes
metro.hostbehave 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:8083then does on an emulator whatdefaults write <bundleId> RCT_jsLocation localhost:8083does 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.hostalso contains colons, but that was already broken (::1:8081is not a valid authority; it would need brackets), so no working configuration changes.Changelog:
[ANDROID] [ADDED] -
metro.hostaccepts ahost:portvalue, matchingRCT_jsLocationon iOSTest Plan:
yarn format-check-kotlinpasses.RNTester built from this branch (
:packages:rn-tester:android:app:assembleDebug), installed on an API 34google_apisarm64 emulator (adb rootis needed to set the property; a Play image refusessetprop, which is a pre-existing limitation ofmetro.host). Metro started withreact-native start --port 8099; nothing listening on 8081.metro.host10.0.2.2:8099BUNDLE js/RNTesterApp.android.js10.0.2.210.0.2.2:8081and fails to connect