dev server returned error code 403 react native

11,113

Solution 1

A) Set the new port for dev server
User command react-native start --port=8088
or
yourproject\node_modules\react-native\local-cli\server\server.js to set the the available port say 8080
now use react-native start to start server on 8080

B) Now to establish communication between emulator and dev server, use below command
adb -s emulator -5554 reverse tcp:8088 tcp:8088
i) 5554 =>emulator port (adb devices command will tell you emulator port but if this command is not working then set the path C:/../android-sdk/platform-tools in Path environemnt variable )
ii) 8088 =>server port

C) run the command react-native run-android

D) Follow below steps updating Dev server path in emulator

i) Ctrl + M for windows to open your dev menu for the emulator.
ii) Click Dev Settings
III) Under Debugging select Debug server host & port for device
IV) Enter the url and port for your application as 10.0.2.2:8088

Solution 2

  1. Press cmd + M (Ctrl + M for windows) to open your dev menu for the emulator (Please make sure your react-native app is open in the active window of the android emulator before using this command)
  2. Click Dev Settings
  3. Under Debugging select Debug server host & port for device
  4. Enter the correct url and port for your application in your case 10.0.2.2:8088

Once you do that you can reload your application and it should work.

Solution 3

1) First set the port number as 8088 in below file

yourproject\node_modules\react-native\local-cli\server\server.js

now build the project.

2) Follow below steps updating Dev server path in emulator

  • Ctrl + M for windows to open your dev menu for the emulator.
  • Click Dev Settings
  • Under Debugging select Debug server host & port for device
  • Enter the url and port for your application as 10.0.2.2:8088
Share:
11,113
helloworld
Author by

helloworld

merge delete

Updated on July 29, 2022

Comments

  • helloworld
    helloworld almost 2 years

    Followed the steps here to try react-native android on a windows box.

    1. On a separate prompt I executed react-native start which is running fine
    2. Started the AVD from AVD Manager
    3. Executed react-native run-android

    BUILD SUCCESSFUL Total time: 27.632 secs Starting the app on emulator-5554 (D:\software\Android\android-sdk/platform-tool s/adb -s emulator-5554 shell am start -n com.awesomeproject/.MainActivity)... Starting: Intent { cmp=com.awesomeproject/.MainActivity }

    1. Executed react-native run-android on a separate console from within same folder

    But I see an error which I'm having hard time to resolve. Please suggest resolution.

    enter image description here enter image description here

    ---EDIT---

    Possibly the issue is that 8081 port is in use by McAfee. So I updated the server.js to run dev port on 8088 and now when I browse http://localhost:8088/index.android.bundle?platform=android I can see JS loading.

    But how do I make android use this address instead of default **10.0.2.2:8081?** I found a file AndroidInfoHelpers.java which contains that 10.0.2.2 path but not sure if that's the way as being a JAVA file I possibly need to recompile whole program. There should be a simpler way to point android app to use a different port for dev server.

    Also, when I execute react-native run-android the first line that gets output says "JS Server not recognized.. Continuing with the build" which likely is shouting the same thing.