From 1075bbb90c537e4c69c9316e6717385b9c618c7e Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 17 Sep 2026 23:40:57 -0400 Subject: [PATCH] Android: honor a port in the metro.host system property 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. --- .../react/modules/systeminfo/AndroidInfoHelpers.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.kt index 2d3581cefac4..ab517f434722 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.kt @@ -92,9 +92,14 @@ public object AndroidInfoHelpers { context.resources.getInteger(R.integer.react_native_dev_server_port) private fun getServerIpAddress(context: Context?, port: Int): String { + val metroHost = getMetroHostPropValue() + // A "host:port" value names the port too, like RCT_jsLocation on iOS. + if (metroHost.contains(':')) { + return metroHost + } val ipAddress: String = when { - getMetroHostPropValue().isNotEmpty() -> getMetroHostPropValue() + metroHost.isNotEmpty() -> metroHost isRunningOnGenymotion() -> GENYMOTION_LOCALHOST isRunningOnStockEmulator() -> EMULATOR_LOCALHOST else -> DEVICE_LOCALHOST