Access docker localhost API from Android Emulator - android

I'm attempting to test my local dockerised API against a staging version of my app.
I don't have access to the repository to build the App myself so I'm relying on changing the IP address within the emulator to point at my local machine and that's where I'm failing.
I've set it to 10.0.2.2 as per the emulator documentation, and when I ping the staging url from the ADB shell (ping mystagingsite.com) it responds data from 10.0.2.2 . But from within the app, the response is always empty. I've tried 127.0.0.1 which obviously won't work, and I've tried my network IP address.
Is what I'm trying to do possible? If it is, what is the right IP address to put in the /etc/hosts file of the emulator and how do I find that address?

Related

Access localhost on laravel valet from Android emulator

I'm using laravel valet to serve an API on a Mac. How can you access it from an Android emulator
As the Android Emulator is different computer than your Mac, you should use the IP address of the Mac (or its name if it is resolved on your network) instead of localhost.
For example if your Mac has IP address 192.168.1.10, then use this address.
Edit the /etc/hosts file on your Android Emulator following the instructions in this SO answer.
Add the following to this file:
myapp.test 10.0.2.2
This will route requests made to myapp.test to 10.0.2.2, which is a static IP address that an AVD uses instead of localhost to access the host.

Access localhost, Mac Android Studio Emulator

I'm running a local http server on port 3000 and i'd like to access that server using an Android emulator. I've tried the following in the browser:
localhost:3000 //
127.0.0.1:3000 // of course I gave my local ip a try
10.0.3.2:3000 // I think this is a genymotion ip?
10.0.2.2:3000 // The most prevailing suggestion was to use this ip
With each of these i'm given this error:
Interestingly when accessing the same in chrome on my desktop:
localhost:3000 // works
127.0.0.1:3000 // doesn't work
Perhaps this is connected? I'm not sure why 127.0.0.1:3000 doesn't work, but that might be a different hurdle altogether.
My /etc/hosts file:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
I've already tried reloading (& disabling) my firewall and proxies.
The emulator i'm using is:
Mac, Android Studio 1.5.1
Emulator : Nexus 5 - API 21, Android 5.0 x86
Use following Service
https://ngrok.com/
It will give you a tunnel to localhost and give you a URL which you can use from anywhere in the world ;)

There is any configuration for this tools eclipse or wamp or android sdk to connect my mobile phone to wampserver

here is any configuration for this tools eclipse or wamp or android sdk to connect my mobile phone to wampserver?
i look this exemple in this site blow i just copy and paste the code in eclipse but the problem is how i can import and export data from my phone to database and Conversely ?
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
If I've understood correctly, you're running a wamp server locally on your computer and you'd like to access that server from your application. The general approach is similar to connecting to any other server, but you'd have to find the right IP-address to connect to. Try this:
First, make sure your server is up and running.
Second, access the server on your computer using one of two addresses:
If you're testing your app on the emulator (AVD), use this: 10.0.2.2, which translates to the localhost-address on your computer.
If you're testing your app on an actual device, you'd have to find your computer's IP-address. On linux, open a terminal and execute the command ifconfig. In windows, I believe it's ipconfig. Use the address listed under wlan0 -> inet addr.
Remember to append the port number your server is running on.
EDIT
Example, given port number is 80:
Emulator: 10.0.2.2:80
Device: 192.168.X.X:80

Can't connect android emulator to look at local sites and services

I'm trying to use an Android emulator to use services running on my local machine. I have a site running under IIS which in my host file looks like this:
127.0.0.1 www.local.company.co.uk
I have several sites running under Apache Tomcat. My host file for Tomcat related sites:
127.0.0.1 internal.localhost.company.com # port:8090
127.0.0.2 external.localhost.company.com # port:8081
127.0.0.3 auth.ws.localhost.company.com # port:8082
127.0.0.8 mysite.localhost.company.com # port:8086
What I have tried so far (in the following steps):
adb pull /etc/hosts
Edit Android host file:
127.0.0.1 localhost
10.0.2.2 myefc.localhost.efinancialcareers.com
adb remount
adb push hosts /etc/hosts
Then I try to visit myefc.localhost.efinancialcareers.com in the browser and am told webpage not found. I’d at least expect it to go to www.local.company.co.uk.
What I would ideally like is to be able to go to any site on my local machine which are specified in the above host file examples.
I am on Windows 7 and using Tomcat 6. The emulator I am using is nexus one.
You need to use the IP address of your server. If you reference localhost from the device it will try to make a connection to itself through the loopback IP address 127.0.0.1.

Android emulator -dns-server usage

I am currently somewhat struggling to get the Android emulator to use a custom DNS server, which is running on localhost (127.0.0.1).
As of now, I have tried various approaches trying to convince the emulator to use my DNS server, so far without success. In the end, it always boils down to the following error message:
### WARNING: can't resolve DNS server name 'localhost'
### WARNING: will use system default DNS server
localhost, however, resolves correctly when supplied to nslookup:
$ nslookup localhost
Server: dnszrh01.xxx
Address: 10.xxx.xxx.xxx
Non-authoritative answer:
Name: localhost.xxx
Address: 127.0.0.1
Using the IP address instead of the hostname also does not help much,
it just changes the error message to:
### WARNING: can't resolve DNS server name '127.0.0.1'
### WARNING: will use system default DNS server
The extra command line I am using to start the emulator reads:
-http-proxy http://proxy.xxx:8080 -dns-server 127.0.0.1 -debug-proxy -verbose
This is happening with Android emulator version 5.0 (build_id
ECLAIR-24846) running on Windows.
Any hint how to get this working is much appreciated!
A couple things...
1) I've noticed I get this error also when I have no network connectivity at all. ie. No wireless or ethernet connection.
2) Excerpt from Emulator guide:
http://developer.android.com/guide/developing/tools/emulator.html#dns
Configuring the Emulator's DNS Settings
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.
On Linux and OS X, the emulator obtains the DNS server addresses by parsing the file /etc/resolv.conf. On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually means that the emulator ignores the content of your "hosts" file (/etc/hosts on Linux/OS X, %WINDOWS%/system32/HOSTS on Windows).
When starting the emulator at the command line, you can also use the -dns-server option to manually specify the addresses of DNS servers to use, where is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter DNS resolution problems in the emulated network (for example, an "Unknown Host error" message that appears when using the web browser).
3) Also see this other StackOverflow question:
Android emulator doesn't use Windows host file?

Categories

Resources