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
@@ -11,6 +11,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
@@ -28,15 +29,19 @@ public class DebugServerException extends RuntimeException {
|
||||
"\u2022 Ensure that the packager server is running\n" +
|
||||
"\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n" +
|
||||
"\u2022 Ensure Airplane Mode is disabled\n" +
|
||||
"\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n" +
|
||||
"\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n";
|
||||
"\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:<PORT> tcp:<PORT>' to forward requests from your device\n" +
|
||||
"\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:<PORT>\n\n";
|
||||
|
||||
public static DebugServerException makeGeneric(String reason, Throwable t) {
|
||||
return makeGeneric(reason, "", t);
|
||||
public static DebugServerException makeGeneric(String url, String reason, Throwable t) {
|
||||
return makeGeneric(url, reason, "", t);
|
||||
}
|
||||
|
||||
public static DebugServerException makeGeneric(String reason, String extra, Throwable t) {
|
||||
return new DebugServerException(reason + GENERIC_ERROR_MESSAGE + extra, t);
|
||||
public static DebugServerException makeGeneric(String url, String reason, String extra, Throwable t) {
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
String message = GENERIC_ERROR_MESSAGE.replace("<PORT>", String.valueOf(uri.getPort()));
|
||||
|
||||
return new DebugServerException(reason + message + extra, t);
|
||||
}
|
||||
|
||||
private DebugServerException(String description, String fileName, int lineNumber, int column) {
|
||||
@@ -56,7 +61,7 @@ public class DebugServerException extends RuntimeException {
|
||||
* @param str json string returned by the debug server
|
||||
* @return A DebugServerException or null if the string is not of proper form.
|
||||
*/
|
||||
@Nullable public static DebugServerException parse(String str) {
|
||||
@Nullable public static DebugServerException parse(String url, String str) {
|
||||
if (TextUtils.isEmpty(str)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user