Skip to content

react-native-xcode.sh script does not extract the correct IP address when en0 is not in use #25460

@richardhyatt

Description

@richardhyatt

The build script react-native-xcode.sh does not extract the correct IP address when generating the ip.txt file when:

  • en0 is not in use
  • en1 is assigned a routable/resolvable IP address
  • Another network interface is present using the 169.254.xxx..xx address space (like Thunderbolt connection between computers)

This prevents hot reloading, reloading or debugging the app when deployed to an iPhone. This occurs because the build script uses the 169.254.x.x as a secondary case when en0 is not present. This address is not on the same network as the iPhone, because it's used in a restricted network, and thus the phone cannot reload from metro or the debugging console.

React Native version:

  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
      Memory: 567.23 MB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.13.0 - ~/.nvm/versions/node/v11.13.0/bin/node
      npm: 6.9.0 - ~/.nvm/versions/node/v11.13.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 28, 29
        Build Tools: 28.0.3
        System Images: android-28 | Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5522156
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.10 => 0.59.10
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Steps To Reproduce

  1. Do not use en0 (wired on iMac)
  2. Use en1 (wireless on iMac)
  3. react-native init MyTestApp
  4. Open project in xcode
  5. Build and deploy to a physical iPhone
  6. Shake iPhone (trigger dev menu) and reload the app

Describe what you expected to happen:

App will hang and then a time out exception will be displayed.

Suggested Fix(s):

Existing code from scripts/react-native-xcode.sh:

# Enables iOS devices to get the IP address of the machine running Metro Bundler
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  IP=$(ipconfig getifaddr en0)
  if [ -z "$IP" ]; then
    IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | cut -d\   -f2  | awk 'NR==1{print $1}')
  fi

  echo "$IP" > "$DEST/ip.txt"
fi

Change to:

# Enables iOS devices to get the IP address of the machine running Metro Bundler
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  IP=$(ipconfig getifaddr en0)
  if [ -z "$IP" ]; then
    IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254' | cut -d\   -f2  | awk 'NR==1{print $1}')
  fi

  echo "$IP" > "$DEST/ip.txt"
fi

Alternatively, the code can look for both en0 and en1 addresses:

# Enables iOS devices to get the IP address of the machine running Metro Bundler
if [[ "$CONFIGURATION" = *Debug* && ! "$PLATFORM_NAME" == *simulator ]]; then
  IP=$(ipconfig getifaddr en0)
  if [ -z "$IP" ]; then
    IP=$(ipconfig getifaddr en1)
  fi
  if [ -z "$IP" ]; then
    IP=$(ifconfig | grep 'inet ' | grep -v ' 127.' | grep -v ' 169.254' | cut -d\   -f2  | awk 'NR==1{print $1}')
  fi

  echo "$IP" > "$DEST/ip.txt"
fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions