From 28748f165b3d8a3a8e9567eb2cfe949cc565b715 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Fri, 12 May 2017 13:17:51 -0700 Subject: [PATCH] Support custom packager port when debugging on Android Summary: This three liner addresses the issue described by Rovack here: #9935 Basically, changing the React Native Packager port from 8081 to, say, 8088 does work, *except* if you want to debug your code with ChromeDevTools (i.e. selecting "Debug JS Remotely" from the Android app dev menu). The analysis of Rovack, pointing to a hard-coded port in DevServerHelper.getHostForJSProxy() was *spot on* - many thanks to him. Closes https://github.com/facebook/react-native/pull/12095 Differential Revision: D5044330 Pulled By: mkonicek fbshipit-source-id: c07f59f700683ffba84f03d44f82b394e2e899c1 --- .../facebook/react/devsupport/DevServerHelper.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 100c52b27..1767bd123 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -320,8 +320,16 @@ public class DevServerHelper { /** * @return the host to use when connecting to the bundle server from the host itself. */ - private static String getHostForJSProxy() { - return AndroidInfoHelpers.DEVICE_LOCALHOST; + private String getHostForJSProxy() { + // Use custom port if configured. Note that host stays "localhost". + String host = Assertions.assertNotNull( + mSettings.getPackagerConnectionSettings().getDebugServerHost()); + int portOffset = host.lastIndexOf(':'); + if (portOffset > -1) { + return "localhost" + host.substring(portOffset); + } else { + return AndroidInfoHelpers.DEVICE_LOCALHOST; + } } /** @@ -551,7 +559,7 @@ public class DevServerHelper { } public String getJSBundleURLForRemoteDebugging(String mainModuleName) { - // The host IP we use when connecting to the JS bundle server from the emulator is not the + // The host we use when connecting to the JS bundle server from the emulator is not the // same as the one needed to connect to the same server from the JavaScript proxy running on the // host itself. return createBundleURL(