mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Android Fix for 9145: No longer hard code build port (#23616)
Summary: ### Problem According to https://github.com/facebook/react-native/issues/9145, the `--port` setting is not respected when executing `react-native run-android`. The templates that report things like what port the dev server runs on are hard coded as well. ### Solution This commit replaces the hardcoded instances of port 8081 on Android with a build configuration property. This allows setting of the port React Native Android connects to for the local build server. For this change to work, there must also be an update to the react native CLI to pass along this setting: https://github.com/react-native-community/react-native-cli/compare/master...nhunzaker:9145-android-no-port-hardcode-cli To avoid some noise on their end, I figured I wouldn't submit a PR until it's this approach is deemed workable. ## Changelog [Android][fixed] - `react-native run-android --port <x>` correctly connects to dev server and related error messages display the correct port Pull Request resolved: https://github.com/facebook/react-native/pull/23616 Differential Revision: D15645200 Pulled By: cpojer fbshipit-source-id: 3bdfd458b8ac3ec78290736c9ed0db2e5776ed46
This commit is contained in:
committed by
Facebook Github Bot
parent
68bca1fbd0
commit
995b4d3049
@@ -142,10 +142,12 @@ public class BundleDownloader {
|
||||
}
|
||||
mDownloadBundleFromURLCall = null;
|
||||
|
||||
String url = call.request().url().toString();
|
||||
|
||||
callback.onFailure(
|
||||
DebugServerException.makeGeneric(
|
||||
DebugServerException.makeGeneric(url,
|
||||
"Could not connect to development server.",
|
||||
"URL: " + call.request().url().toString(),
|
||||
"URL: " + url,
|
||||
e));
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ public class BundleDownloader {
|
||||
// Check for server errors. If the server error has the expected form, fail with more info.
|
||||
if (statusCode != 200) {
|
||||
String bodyString = body.readUtf8();
|
||||
DebugServerException debugServerException = DebugServerException.parse(bodyString);
|
||||
DebugServerException debugServerException = DebugServerException.parse(url, bodyString);
|
||||
if (debugServerException != null) {
|
||||
callback.onFailure(debugServerException);
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.devsupport;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -261,7 +262,7 @@ public class DevServerHelper {
|
||||
|
||||
public boolean doSync() {
|
||||
try {
|
||||
String attachToNuclideUrl = getInspectorAttachUrl(title);
|
||||
String attachToNuclideUrl = getInspectorAttachUrl(context, title);
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder().url(attachToNuclideUrl).build();
|
||||
client.newCall(request).execute();
|
||||
@@ -367,11 +368,11 @@ public class DevServerHelper {
|
||||
mPackageName);
|
||||
}
|
||||
|
||||
private String getInspectorAttachUrl(String title) {
|
||||
private String getInspectorAttachUrl(Context context, String title) {
|
||||
return String.format(
|
||||
Locale.US,
|
||||
"http://%s/nuclide/attach-debugger-nuclide?title=%s&app=%s&device=%s",
|
||||
AndroidInfoHelpers.getServerHost(),
|
||||
AndroidInfoHelpers.getServerHost(context),
|
||||
title,
|
||||
mPackageName,
|
||||
AndroidInfoHelpers.getFriendlyDeviceName());
|
||||
|
||||
Reference in New Issue
Block a user