On my local laptop I have a bunch of sites running using docker and made accessible in my /etc/hosts like so:
> 127.0.0.1 www.example.local
> 127.0.0.1 api.example.local
> 127.0.0.1 connect.exampe.local
Using Ionic I am emulating android: ionic cordova emulate android
Now when I got the browser on the android and I type it in www.example.local, I cannot access the site. But it works fine from my local. I assumed they would be using the name network settings. What configuration am I missing?
I would imagine this device is acting in similar fashion as a virtual machine. In which case, the network is bridged but different. 127.0.0.1 on this device likely points to the device itself. You will need to find (or create) the ip of your computer that your device is familiar with
If you are running on a mac, you can use the following commands to create an alias to the loopback adapter which the device should be able to see.
(NOTE: the dns you setup in /etc/hosts may not work)
ifconfig lo0 alias 172.16.123.1 # Allows emulator to use 172.16.123.1 for localhost
ifconfig lo0 -alias 172.16.123.1 # removes alias
Source of this info:
https://stackoverflow.com/a/624660/1991100
Related
I'm using Easyphp to host my local website on windows and It works flawlessly. Now I'm trying to launch the website from my android phone. But It doesn't seem to work by just typing :
http://pclocalip:8080
or
http://pclocalip
As other web hosts like XAMPP and WAMP allow it by just doing that.
If you are using default android emulator
The first step is to start the AVD with an increased partition size otherwise you may get an out of memory error when you try to save the modified hosts file
emulator -avd MyAVD -partition-size 128
You then have to remount the system partition so that it is writeable
adb remount
Then copy the hosts file from the emulated device to the host machine
adb pull /etc/hosts
Edit the hosts file so that it includes mappings for all relevant virtual host names
127.0.0.1 localhost
10.0.2.2 pclocalip
Then copy the updated file back to the emulated device
adb push hosts /etc/hosts
You should then be able to visit http://pclocalip in the emulator’s browser and see the correct site
PS: Note that 10.0.2.2 here is the localhost IP address of your machine that run the AVD
There is a module especially for that : www.easyphp.org/documentation/devserver/mobile-for-devserver.php
"With the module "Mobile", you can test your code on your mobile phone / tablet and see if your website / application is mobile friendly."
In my current Android Emulator with API 26 I'm trying to access with it's browser to a localhost subdomain set in the android emulator hosts file with no success.
I successfully managed to root my emulator and modify it's /etc/hosts file (pushing a local file and with busybox mini vi implementation). Some of the successful tests that I made in the browser and with the ping command from adb shell are as follows (where 192.168.0.10 is my current assigned host ip):
192.168.0.10 source
192.168.0.10 source.api
192.168.0.10 source.api.local
10.0.2.2 source
10.0.2.2 source.api
10.0.2.2 source.api.local
but with localhosts subdomains mappings I can only ping the domain from adb shell with success. The browser displays an ERR_CONNECTION_REFUSED error in the next host mappings:
10.0.2.2 something.localhost
10.0.2.2 something.something.localhost
Any ideas on why this is happening?
EDIT:
The current problem only happens in my macOS 10.14, I couldn't reproduce the problem in Ubuntu 18.04.
The problem is with the Multicast DNS (mDNS) implementation of macOS, when using the top-level domain .local
Bonjour... "will automatically resolve the private IP addresses of link-local Macintosh computers running MacOS and mobile devices running iOS if .local is appended to their hostnames."
RFC 6762 Appendix G recomends the following private namespaces instead of .local|.localhost to avoid conflicts.
.intranet.
.internal.
.private.
.corp.
.home.
.lan.
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
I having problem in using my system hosts file details in Android Emulators.
I have my website (www.example.com) deployed in Webserver.
I am trying to access those website in Emulator from my desktop.
My desktop has a hosts file with the entry of
10.xx.xx.xx www.example.com
I am trying to access the www.example.com from the android emulator - browser and it is not working.
I took a reference from the below website, but most of the website says how to use the hosts file if the website is deployed in the same server.
http://sadhanasiblog.blogspot.in/2012/07/local-environment-setup-for-android.html
Please let me know if anyone has answers. Thanks in Advance.
-Senthil
With latest Android studio and tools. You can now use follow this instructions. You only need to run this once per emulator.
Start the emulator with following command. This command is located under your [sdk folder]/tools directory
emulator #[emulator name] -writable-system
Open another command prompt and then switch your directory to [sdk folder]/platform-tools and run following commands
adb root
adb remount
adb shell
echo '10.0.2.2 [localserver dns name]'>>/etc/hosts -- example echo '10.0.2.2 xxxx.com'>>/etc/hosts
One important thing to check is, if you create your HOSTS file on Windows or MacOS machine, that the HOSTS file contains linux line endings ('\n', LF, #10, #0x0A). Android ignores the HOSTS file if it contains Windows' 2-char line endings ('\r\n', CRLF, #13#10, #0x0D0A) or MacOS-style line endings ('\r', CR, #13, #0x0D).
Except for letters/numbers/dots (used for IP and host names) the file should contain only characters 0x20 (space), 0x09 (tab) and 0x0A (new line).
To acces to your localhost the IP is
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
From Android docs:
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).
At your console use:
emulator -avd <you_avd_name> -dns-server <serverList>
I used when I had to connect to a VirtualBox with a linux distro on the same PC and it worked from the emulator webview http://10.0.2.3/servlet-name
Reference: Emulator Networking
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.