I've started android emulator app and trying to open from embeded browser locally started web-site, but local dns name (from /etc/hosts) is not resolved. Is there any option to enable local resolving?
Refer this URL. The issue is 127.0.0.1 is not the correct IP for accessing local server sites on emulator.
http://localhost:8080/MyTestPage.html // URL to use in computer browser
http://10.0.2.2:8080/MyTestPage.html // URL to use in emulator browser
However, you need to do some configuration changes as suggested in the URL.
Here's how to access a locally hosted website in the Android emulator.
Use IIS/Apache to host the application.
For some obscure reason, Android Virtual Device would not let you connect to the development server created by Visual Studio.
Once you host the application, use your IP address as the web address to connect to the local website. "localhost" just won't work with the AVD. Just go to the command prompt and type ipconfig to get your local ip address. You should be looking for IPv4 Address
Here's Android AVD connecting to Apache (XAMPP)
Here's connecting to IIS
Good Luck everyone and happy testing!!
You should specify your local ip address in browser, something like 192.168.xx.xx
Related
I am trying to access a virtual machine url in browser of android emulator to build an application. But I keep getting this error
The webpage at
https://virtualmachinehost.name.com:1443/myserviceurl
net:ERR_NAME_NOT_RESOLVED
I did some google search also. I can access any other website on this browser. I also tried to add the ip address of this virutal machine with its hostname in hosts file. But nothing has helped.
Network Setup:
Host machine IP - 10.X.X.130
VM IP - 172.X.X.238
emulator client IP - 192.X.X.102
"If I ping domain name, I get unknown host. But if I ping ip addess of that VM, it is correctly pinging that VM"
This indicates that the /etc/hosts modification you made is not working. If it was working correctly then the domain name would map to the ip address and you would be fine. I noticed that you are using a hierarchical domain name (IE: top level domain is com, subdomain is virtualmachinehost, and hostname is name). This has to be in the hosts file also in order to work, but there may be an easier solution.
May recomend that you simplify your hosts file and url by doing the following:
In the host file change the entry to: machinename <IP address>. do not add a domain or subdomain
Changed your referenced URL to: https://machinename:1443/myserviceurl
Restarting the computer solved this for me.
Your problem is that there is no direct route from your emulator to your virtual machine through your host machine. You need to setup a routing table on the host machine to translate the addresses.
A quick and simple solution would be to have both the emulator and VM be NAT-ed with the host machine.
More info on NATing:
https://www.vmware.com/support/ws55/doc/ws_net_configurations_nat.html
Restarting the emulator resolved this issue for me.
This question already has answers here:
How do I use a mobile phone to open localhost:4200?
(11 answers)
Closed 3 years ago.
I know from this question and answer on Super User Site running on localhost on desktop is unreachable on android device (PS: this question continues on the question in the link) that the command ng serve opens a bad configured webserver.
The question is how could I run my site on an Android device without deploying my site. I'll try to run the site on this url http://192.168.0.168:4200 using Angular-CLI.
try ng serve --host option as explained in this issue: https://github.com/angular/angular-cli/issues/1793 comment by intellix.
ng serve --host 0.0.0.0
Find your local IP address by following this
Navigate to <local IP adress>:4200 from any device on the same network.
NOTE: If you get CONNECTION_REFUSED just disable your firewall and you should be good to go.
otherwise, try https://ngrok.com/ to open a tunnel from your local network to your computer's localhost. Basically your computer forwards the 4200 port to an external IP and port that any device on the network can access.
First verify your machine IP Address.
On Windows, type ipconfig in Prompt (copy IPv4).
On Mac, type ifconfig |grep inet in Terminal (copy inet).
In my case this is 192.168.0.10.
Next, type ng serve --host 192.168.0.10.
Ok, your app on air for all devices on same network.
Now only http://192.168.0.10:4200/ will work, localhost not more.
When i tried using
ng serve --host local_ip_address
I was facing
Invalid header Request
This issue was solved using --disable-host-check
ng serve --host local_ip_address --disable-host-check
As an addition to all the answers above, you might need to adjust your proxy settings on your device. For my Android Phone, this was:
Settings
Wifi
Long Click your desired Network
Modify Network
Click advanced/extended Options
Set proxyHostname: localhost and proxyPort: 4200 and bypassProxyFor: hostIpAddress
I open my Angular2 App on Mobile device using Chrome Remote Device.
You just have to connect your phone to your pc and sync it with chrome.
Than do the port forwarding as described at the link above.
After connect your device, run your Angular app serve with ng serve --public-host
Now you can access your app in localhost:4200 from mobile device.
for Ubuntu people:
get the ip address writing this in the terminal:
hostname -I
you will get an ip address something like 192.168.0.0
and then you can just serve the app with:
ng serve --host ip_address
and then you can just open the browser in your mobile with:
http://ip_address:4200
I'm having trouble accessing my server (WAMP) using my real android device. I have an app that downloads the data and parsing it to my listview. In the emulator everything is working fine using "10.0.2.2" I tried 10.0.2.2:80, 10.0.2.2(without port #), (my laptop's ip) 192.168.254.103:80 and 192.168.254.103 (without port #) in my url. My WAMP is online and I even tried turning off firewall. Is there something missing?
UPDATE
I tried browsing via my phone's browser the ip address of my laptop and it says "FORBIDDEN". i tried configuring the httpd.conf of apache based on what I've researched but still can't access the server. please help.
Turn off Firewall -
Give permission to "WAMP folder" by using Folder
sharing options - Basically access to "All" for read, write
Is there a way to test android app by using local (ie computer on which emulator is running) JSON file instead of giving it URL of online file. In my university we have proxy login which means that android apps cant access the internet so i need to use a file on my system for testing app on emulator. do i need to setup a server like wamp or can i directly pass filepath as argument to JsonArrayRequest?
I dont have a clue about other workarounds, but you can set up Wamp Server or Xamp Server and call the url from emulator,
And yes in order to access the localhost inside Emulator you can use following IP:
10.0.2.2 for Default emulator and 10.0.3.2 for GenyMotion
and yes to mention i got the GenyMotion reference from this answer link to answer
I am getting google.com inside my WebView, but am not getting my localhost in that.
Can anybody help me?
Use 10.0.2.2 instead. This is a special ip address that the emulator routs to local host on your dev machine. assuming that emulator and the webserver are running on the same machine.
Make sure you are loading WebView with full Urls.
http://www.google.com
http://10.0.2.2/
and not:
www.google.com
google.com
All of these will work while using Browser, but you must supply a full valid url for WebView. Banged my head against the keyboard for an hour figuring that out.
If you're having connectivity issues in the emulator, try overriding the dns in the build path.
Window > Preferences > Android > Launch
Default emulator options: -dns-server 8.8.8.8
I have created a website and published it in my local computer using IIS, I tried to access this site in the android emulator using WebView:
http://localhost:83
with the same results as the OP.
I changed to:
http://10.0.2.2:83
and worked.
Try your actual ip [with the port number if required] instead of localhost.
Just type localhost name and port like this: http://127.0.0.1:80
If you're using a physical device to run, then,
make sure your website is running at 192.168.x.xxx:port
set the full url in your activity, such as,
mwebView.loadUrl("http://192.168.1.107:8000/");
add
android:usesCleartextTraffic="true"
in AndroidManifest.xml to fix 'cleartext not permitted' error caused for not using https
If in emulator, then,
host website in localhost (127.0.0.1:port)
for url
mwebView.loadUrl("http://127.0.0.1:3000");
previous 3rd step
(Make sure to remove the manifest permission before release. Or it would be a security concern for your app.)
I added the IP Address of the local server and it is working fine.
You can find you ip address by going to
COMMAND PROMPT
type> ipconfig
Now, add the ipv4 IP Address shown in your Webview URL. It will work fine.