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
This commit is contained in:
ivmarkov 2017-05-12 13:17:51 -07:00 committed by Facebook Github Bot
parent dc783d97e8
commit 28748f165b

View File

@ -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(