skip to Main Content

It was working properly few days ago but suddenly it stopped working. When I’m trying to communicate with my development server "http://192.168.13.55:8000/" both IOS and Android emulators are working fine, but when I connect my phone, it’s not working anymore.

I’ve tried adding android:usesCleartextTraffic="true" on AndroidManifest.xml and also even tried commenting out

...
      NetworkingModule.setCustomClientBuilder(
          new NetworkingModule.CustomClientBuilder() {
            @Override
            public void apply(OkHttpClient.Builder builder) {
              // builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
            }
          });
...

on ReactNativeFlipper.java, deleted node_modules and still no luck

System:
    OS: macOS 13.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 158.53 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.15.1 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.11.0 - /usr/local/bin/npm
    Watchman: 2022.12.12.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.12.1 - /Users/raybi/.rvm/gems/ruby-2.7.6/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 27, 28, 29, 30, 31, 33
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 33.0.0
      System Images: android-31 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8193401
    Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.6 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.7 => 0.71.7 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Can anyone help me to get rid of this issue?

2

Answers


  1. Yes the device might not be able to access the local network like this.
    Try using a service like ngrok to expose the required port, and use it in the app, similar to any hosted server.

    Login or Signup to reply.
  2. To Connecting to the development server you do follow:
    run adb devices cmd to get device name.
    then run this code: adb -s <device name> reverse tcp:8081 tcp:8081
    . In react native code you replace BASE_URL_MYSERVER = 'http://192.168.1.10:5185/api'
    where 192.168.1.10 is your PC’s IP.
    Note that you must allow usb debugging on the device.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search