React Native "Could not connect to development server." - android

I know this already has been asked a few times, but no solution has worked for me. In fact, sometimes it does connect and my app runs on the device, but one or two attempts later, with no change, it suddenly does not. My app always runs in the emulator.
I've set my IP in AppDelegate.m and RCTWebsocketExecutor.m. I've set App Transport Security Settings to "Allow Arbitrary Loads" and even set it to allow my IP. My app is using the react-native-storage to store a user, not sure if that could cause any problems while testing.

I figured it out. It was a network problem. I used ngrok to solve my problem.

What worked for me was to trigger the developer's menu entering :
adb shell input keyevent 82
In Dev Settings > Debug server host & port for device, I entered the local IP of my machine followed by port 8081, i.e. 192.168.0.1:8081.
To get my local IP address, I used the ifconfig command, and I locate the inet field value of the Wifi interface, i.e. wlp2s0.
I hope this helps !
EDIT
To be perfectly fair, this is actually explained quite well in the documentation.

Related

failled to access to localhost using volley library [duplicate]

What can I do in the Android emulator to connect it to my localhost web server page at http://localhost or http://127.0.0.1?
I've tried it, but the emulator still takes my request like a Google search for localhost or worse it says that it didn't found the page while my web server is normally running.
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead.
You can read more from here.
Use 10.0.2.2 for default AVD and 10.0.3.2 for genymotion.
I used 10.0.2.2 successfully on my home machine, but at work, it did not work. After hours of fooling around, I created a new emulator instance using the Android Virtual Device (AVD) manager, and finally the 10.0.2.2 worked.
I don't know what was wrong with the other emulator instance (the platform was the same), but if you find 10.0.2.2 does not work, try creating a new emulator instance.
Try http://10.0.2.2:8080/ where 8080 is your port number. It worked perfectly. If you just try 10.0.2.2 it won't work. You need to add port number to it. Also if Microsoft IIS has been installed try turning off that feature from control panel (if using any windows os) and then try as given above.
You can actually use localhost:8000 to connect to your machine's localhost by running below command each time when you run your emulator (tested on Mac only):
adb reverse tcp:8000 tcp:8000
Just put it to Android Studio terminal.
It basically sets up a reverse proxy in which a http server running on your phone accepts connections on a port and wires them to your computer or vice versa.
according to documentation:
10.0.2.2 - Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
check Emulator Networking for more tricks on emulator networking.
For My Mac OS mountain Lion device :
http://10.0.2.2:8888
Works perfect !
If you using Android Emulator :
You can connect to your Pc localhost by these IPs :
10.0.2.2:{port of your localhost} => if you set your machine port in xamp you must use that port . In my case 10.0.2.2:2080
Also you can use your network adapter IP .In CMD write ipconfig and find your adapter ip address :
If emulator can not connect to this IPs close the emulator an open it by cold boot from AVD Manager :
If you using Genymotion :
You can connect to machine localhost by this IP : 10.0.3.2:{port number}
Or your adapter IP address as I explained above: in my case : 192.168.1.3:2080
I needed to figure out the system host IP address for the emulator "Nox App Player". Here is how I figured out it was 172.17.100.2.
Installed Android Terminal Emulator from the app store
Issue ip link show command to show all network interfaces. Of particular interest was the eth1 interface
Issue ifconfig eth1 command, shows net as 172.17.100.15/255.255.255.0
Begin pinging addresses starting at 172.17.100.1, got a hit on `172.17.100.2'. Not sure if a firewall would interfere but it didn't in my case
Maybe this can help someone else figure it out for other emulators.
Allowing PWA installation
First of all, install the Android debug bridge:
$ sudo apt install adb android-sdk-platform-tools-common
Start your Android emulator as usual, e.g.:
$ ~/Android/Sdk/emulator/emulator -avd Pixel_3a_API_30_x86
Only then, configure a reverse proxy on the bridge of the Android emulator that will forward localhost HTTP requests to the appropriate port (e.g. 8000) of the localhost server running on your host computer and vice versa:
$ adb reverse tcp:8000 tcp:8000
A progressive web application (PWA) being served on localhost:8000
or 127.0.0.1:8000 will be installable and connect to its service-worker.js. Whereas PWA installation is not allowed from IP address 10.0.2.2.
Caveat: adb reverse tcp:8000 tcp:8000 needs to be reissued after each Android emulator evocation.
Hence, a bash script to launch an Android emulator, followed by a reverse proxy, would look like this:
#!/usr/bin/env bash
$HOME/Android/Sdk/emulator/emulator -avd Pixel_3a_API_30_x86 > /dev/null 2>&1
adb reverse tcp:8000 tcp:8000
The accepted answer is correct, but didn't work in my case. I had to create the virtual device with the company VPN-client on the host machine turned off. This is quite understandable as many company networks use adresses starting with 10 (private network range), which could interfere with the special address 10.0.2.2
If you are in windows you can go to simbol system and write ipconfig and check what ip is assigned to your machine.
FOR ANYONE TRYING TO REACH A LOCAL IIS Server (ASP.NET)
For me, the accepted answer was not enough. I had to add a binding for 127.0.0.1 in the applicationhost.config, which was at the root of my ASP.NET solution.
Despite reading all the answers here and elsewhere, I have lost several hours trying to debug this issue, as the address 10.0.2.2 did not work, even in Chrome browser. If the same is happening to you, here is a step-by-step guide to try to debug and hopefully fix your issue.
Check emulator gateway is 10.0.2.2
Inside the emulated Android, go to Settings > WiFi, check if it is connected to AndroidWiFi hotspot (which represents your host computer), and then click on Advanced at the bottom, then check the Gateway address: it should point to 10.0.2.2 . If not, then you have another issue, maybe changing proxy settings can fix your issue, see here how to do that with Android Studio since 2022, as the proxy setting is now hidden away: How to configure proxy in emulators in new versions of Android Studio?
Check if your server is accessible from your host computer
Simply open a web browser and type http://localhost:<port> to see if your local web app is accessible. If not, then you likely have an issue with your local server parameters.
Check if your server is accessible from the emulator
Open Chrome browser, and point it to http://10.0.2.2:<port> (for genymotion, replace with http://10.0.3.2:<port>). If your web app shows up, great, you're done. If not, then test the other steps below to pinpoint the root issue.
Test with another server
In case your web app can be accessed from your host computer, but not inside the emulator, the root cause can be that your local server is restricting access to some interfaces for some reason, likely for security reasons.
To check this, try to use another server, just a simple HTTP server will do, such as http-server with nodejs, or python -m http.server 8000 with Python 3.
Then, try to access this simple server from your emulator's Chrome browser, eg, http://10.0.2.2:8000. If it works, then this confirms that your local server is restricting access to some interfaces. You need to read your local server's documentation to broaden permissions.
For example, in my case, my server was angular-cli (AngularJS), which by default restricts serving only to localhost. To make it work, I had to use ng serve --disable-host-check --host 0.0.0.0 instead of just ng serve, as suggested in this other question. The --host 0.0.0.0 instructs the webserver to serve all interfaces. Similar arguments can be provided to most webservers.
An alternative might be to disable some unused adapters, especially virtual ones such as VPNs.
Your Android app permissions to cleartext
Now, your web app should be accessible from inside the emulator, using Chrome app, with the URL http://10.0.2.2:<port>. The last piece of the puzzle is to add permissions in your Android app to access 10.0.2.2 and especially cleartext if your local webserver is not equipped with a SSL certificate (the most likely scenario for a local development webserver - just check if https://localhost:<port> works or only http://localhost:<port> from the host computer). This will allow your Android app to access your local webserver, just like Chrome does.
Adding specific permissions to access cleartext (ie, http://) from your Android app is necessary since Android 9 (API 28) upwards. There are several ways to configure your Android app to add this permission, see: https://stackoverflow.com/a/50834600/1121352
Conclusion
Accessing the host from the Android emulator can be tricky, but by careful step-by-step debugging, it can be possible to overcome the issue in most cases.
A last alternative, probably faster, is to get a paid subscription to services such as ngrok, but the free version is useless as they necessarily open the webapp in a web browser, outside of your Android app's webview.
I do not know, maybe this topic is already solved, but when I have tried recently do this on Windows machine, I have faced with lot of difficulties.
So my solution was really simple. I have downloaded this soft
http://www.lenzg.net/rinetd/rinetd.html followed their instructions about how to make port forwarding and then successfully my android device connected to make asp.net localhost project and stopped on my breaking point.
my rinetd.conf file:
10.1.1.20 1234 127.0.0.1 1234
10.1.1.20 82 127.0.0.1 82
Where 10.1.1.20 is my localhost ip, 82 and 1234 my ports
Also I have craeted bath file
for easy life yournameofbathfile.bat, put that file inside rinedfolder. My bath file:
rinetd.exe -c rinetd.conf
After starting this soft, start your aps.net server and try to access from android device or any device in your local network(for example Computer ABC starts putty) and you will see that everything works. No need to go to router setting or do any other complicated things.
I hope this will help you. Enjoy.
Another workaround is to get a free domain from no-ip.org and point it to your local ip address.
Then, instead of using http://localhost/yourwebservice you can try http://yourdomain.no-ip.org/yourwebservice
I know this is old, but if you find that 10.0.2.2 is not working as the computer IP, follow these instructions to find it

Debugging android app on phone against local dev server (Google Endpoints) fails to connect with router

I've an android app installed on my phone (debug build) and a local dev server. The app is using GAE Endpoints. I've updated the API builder by adding
b.setRootUrl("http://[myIP]:8080/_ah/api");
However, the app cannot connect. I've verified the dev server is up and running.
As a test, I tped
http://localhost:8080/
in by browser and I get the api explorer, etc.
However, if I do
http://[myIP]:8080/
I get "this webpage is not available". So clearly that must be the root cause.
The way I get my IP address is by running ipconfig in a cmd.
I tried turning off my firewall but that didn't make any difference.
Any and all help much appreciated. Thank you.
Figured it out.
i have a router so need to go into my router settings and add a 'virtual server' (that feature may be called something else for your router) redirecting from my ROUTER ip address (not what you get from ipconfig), and a port (whatever you want, need to use it in the setRootUrl), to my server address (what you DO get from ipconfig) and the local dev server port (typically 8080)
when i start my server in Android Studio i need to specify address 0.0.0.0, can be easily done in Android Stuiod by editing the run config (don't forget to restart it after that change)
update b.setRootUrl to point to the router ip address from 1. and the port you picked in 1. as well (don't forget to rerun your app after the update which will re-install it on your phone)
disable firewall -- however that's unsafe so instead i've created a special rule for this connection. (when setting inbound rules, a big gotcha is that there are usually predefined rules to block ALL connections from Java SDK/JRE for all installed versions on your system which will take precedence. You would need to modify those: I wouldn't advise disabling the whole rule, but you can modify to specific ports as such Ports: 1-[your server port-1], [your server port + 1, 65535].
The combination of those four works for me. Hope this helps someone!

How to connect to kivy-remote-shell?

This seems to be a dumb question, but how do I ssh into the kivy-remote-shell?
I'm trying to use buildozer and seem to be able to get the application built and deployed with the command, buildozer -v android debug deploy run, which ends with the application being pushed, and displayed on my android phone, connected via USB.
However, when I try ssh -p8000 admin#127.0.0.1 from a terminal on the ubuntu machine I pushed the app from I get Connection Refused.
It seems to me that there should be a process on the host (ubuntu) machine in order to proxy the connection, or maybe I just don't see how this works?
Am I missing something simple, or do I need to dig in a debug a bit more?
When the app is running, the GUI will tell you what IP address and port to connect to.
127.0.0.1
This indicates something has gone wrong - 127.0.0.1 is a standard loopback address that simply refers to localhost, i.e. it's trying to ssh into your current computer.
If this is the ip address suggested by kivy-remote-shell then there must be some other problem, though I don't know what - does it work on another device?
Don't know you found the answer or not. But what i have understood is that you are trying to connect android device from Ubuntu. If I am right then (go on reading) you are following wrong steps.
First :- Your Ubuntu does not have ssh server by default so you get this error message.
Second :- You are using 127.0.0.1 address i.e your Ubuntu machine itself.
Method to do this shall be
Give your android machine a static address or if it gets dynamic its OK.
know the IP address of android and then from Ubuntu typessh -p8000 admin#IP_Of_andrid_device and this should solve the issue.

How can I get my android emulator use my computer's VPN interface?

My company requires VPN to connect to our dev systems and for the first time I'm trying to work on an android app from home. Turns out the emulator doesn't want to use the VPN interface so even though I have connectivity to our dev systems on my VPN-connected laptop the emulator that's running on it does not.
I have thought of 3 solutions to this:
run a VPN client on the emulator, but I was hoping for a simpler solution than that
setting up a proxy server on my local machine
forwarding a port on my local machine
2 and 3 can probably work, but I'd still like to know if there is an easy way to get the emulator to use the VPN interface without a workaround.
I'm running OS X 10.7 and I've already tried adjusting the interface priority order with network>>set service order.
I suppose I can dust off the old dell and try it there, but I would expect the same results.
First start your vpn connection and then restart the emulator, now the emulator should use the host vpn connection.
it's mostly because of the DNS issue, according to the android doc:
At startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4, 10.0.2.5 and 10.0.2.6 as needed.
I encountered this issue and tried something on dns settings but I could not solve it. As #machado said in the comment section below you should boot the emulator via "Cold Boot Now" option. I hope this helps.
What I do on my mac is just make sure 'send all traffic over vpn' is checked.
You'll find this setting after you click advanced while having your vpn connection selected in network preferences.
Works well for my situation, but may not depending on the type of VPN you're connecting to.
I had the same issue and solved it by connecting to cisco vpn after the android emulator has started and connected to the internet.
Works for me in windows 7
I setup a vpn connection on Windows. Then I started the emulator. The emulator and everything on my pc started to use that vpn connection.

Accessing intranet in Android emulator

I'm trying to test an intranet site in the Android emulator, but I can't seem to get the emulator to access our intranet. For example, the site I'm trying to access is at http://compass/messages, but trying that page in the browser gives me a Google search result page instead of the intranet site.
I can access the INTERNET with the emulator, but not the INTRANET. I can access the intranet from the host machine, and from the iPhone simulator on the same machine.
I'm assuming there's some sort of weird command line thing I need to do, but I'm pretty clueless...any ideas?
After a tremendous amount of searching with no answer, I was able to access my local dev server by substituting the domain with the ip address. For example, instead of:
http://compass/messages
use this (with your server's IP address)
http://172.33.22.1/messages
It works in the Android emulator browser, and also from a WebView in the app in the emulator. I don't know why this works, but it does for me. Hope it helps someone else.
I was having the same problem and I wasn't been able to find any solution anywhere. What I finally did (after playing around with port forwarding) was to use ssh to create a tunnel to the remote machine:
ssh -L 5555:localhost:5555 10.0.1.14
This should allow you to connect to the local machine's IP address in the emulator (10.0.2.2) and reach the other machine in your network (on the specified port).
If anyone has a better solution for accessing the local network from the android emulator I'd love to hear it.
Intranet site may require proxy.
You can set the proxy in Settings
I have solved this problem by following steps:
adb shell
set setprop net.dns 10.10.20.19(your pc's ip)
restart your emulator.

Categories

Resources