I'm trying to do the react native 'hello world', and I'm using usb debugging on my android.
I ran react-native run-android
, then react-native start
.
I can view the js file in localhost
, but get 'could not connect to development server' message on my phone.
I followed the instructions to run adb reverse tcp:8081 tcp:8081
, then realized that command doesn't exist, so I ran adb forward tcp:8081 tcp:8081
instead.
Still no luck. Using [email protected], ubuntu 14.04. My phone is nexus 5 on android 6.0.1.
How can I allow my phone to access my localhost
?
By the way, it is working over wifi, but I'd like to get it working over usb.
Just another scenario, this error happened to me when I forgot to run react-native start
command. I usually follow the steps here when I start new project. The steps in a nutshell are as follows (Android in my case):
inside the directory where you want to create your new project, open your command line and run:
$ react-native init <Your new project name/it is also the registration name>
$ cd <the new directory you created>
$ react-native start //This is the step that I forgot
Open a new command prompt and run the following inside the same directory(you just created) to launch the app on your AVD.
$ react-native run-android
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
You'll find in the file index.android.js in the home directory of your project, the last line contians the App registry using the same name you used in the first command above
adb reverse tcp:8081 tcp:8081
Only works for android 5.0 + for running app on devices with android versions lesser than 5.0 hit following command after npm start
is done in Terminal (in app directory folder).
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
now run the app, it will work. Only drawback is that every time you make a change you need to fire the command again and run the app again.
I found the solution :)
I am on ubuntu 16, so, I used command ip addr show which gave me my computer ip address.
I used this ip address and I was able to access localhost on my mobile.
Finally I added the ip address and port no to devsettings of android phone and My app was able to access development server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With