I have spent a lot of time trying to figure out how to load my local by Flywheel wordpress website into my Android Emulator.
For iOS, it works like a charm: http://mylbfwsite.local/nameofpage/
For Android, I have looked all over the Internet, and have tried everything I could find, to no avail.
I am thinking, someone on this forum must know!
Please, help and let me know how you do it : )
I am working on a mac…
Thank you!
Hey @marhab –
I’m not quite sure how to do that since I’ve never worked with the Android emulator.
This sounds like it is going to be tricky because each of these systems is on its own virtual network. Since the iOS emulator has tighter integration with Mac OS, it’s probably using the Host machine’s hosts
file to help resolve the Local site’s domain.
If I were to guess, you’ll likely need to somehow to update the hosts
file of the Android emulator so that it points to the IP address that the local-by-flywheel
vm is using.
One other option might be to use something like BrowserSync: https://www.browsersync.io/ with it’s proxy
option so that the site would be accessible to any device that’s on the same LAN.
This can slow things down in terms of multiple requests bouncing around, but it might be the easier option.
Hi Ben!
Thank you so much! It is hard to believe that I am the only person using Local to connect to an Android Emulator! The iOS Simulator works like a charm…but for my demo, I need both.
And, I think you are correct to assume that I need to edit the hosts file on the Android emulator (which of course, it being Google, is not very easy
However maybe you can tell me how to find out what IP address the local-by-flywheel vm is using.
I have followed advice from Megan Garwood, as she mentioned having connected an Android Emulator:
https://megangarwood.com/blog/local-by-flywheel-on-lan/
So, I had 2 adapters:
NAT, with IP 10.0.2.15
Host Only with IP 192.168.95.100
And from Megan’s advice, I added Bridged Adapter with WiFi IP is 10.0.0.71
I am enclosing my log files, just in hope that you can tell me which is the IP to use in my hosts file, i.e the one that you call “the IP that the local-by-flywheel vm is using”
I have asked Megan how she connected to Android, but I haven’t received a response so far.
Thank you again for any help you can give me!
Martine
local-by-flywheel 3.56.47 PM.log (736 KB)
error.log (136 KB)
Hey @marhab –
By default the IP for the virtual machine is 192.168.95.100
. Sometimes that IP is already being used, so it’s possible that this isn’t the IP.
You can verify the IP of the VM in a couple of ways.
Looking at the Local log, there are a few lines that look like this:
May 24, 2019, 2:27 PM PDT - info: [main/set-docker-env] Received Docker Machine env. export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.95.100:2376"
The DOCKER_HOST
value should be the correct IP. You might need to scroll to the bottom of the log and work your way up if that value has changed.
Another option is to open the Hosts file and see what the IP address for the sites that Local is adding to that file.
Here’s a blog post that outlines how to open that file on various Operating Systems:
You should see the contents of that file look something like:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
## Local by Flywheel - Start ##
192.168.95.100 astra.local #Local Site
192.168.95.100 www.astra.local #Local Site
## Local by Flywheel - End ##%
The items between the ## Local by Flywheel
block should be the urls for the local site. So in the above example, I can take the IP for the astra.local
site and be pretty sure that’s the IP of the VM.
Hope that helps get you what you need. Let us know if you need anything else!
Hi Ben!
I am so very appreciative of your sending me these directions! I think you have understood exactly what I need.
Unfortunately, I tried every single combination of what you told me, and nothing works so far.
I tried:
http://192.168.95.100:2376/myfile - Error: ERR_INVALID_HTTP_RESPONSE
http://192.168.95.100/myfile - Error: I get this from Local by Flywheel:
So, I looked at the router log, and saw this:
2019/06/03 21:02:26 [error] 6#6: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.95.1, server: wrongserver.local, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://192.168.95.100:4004/favicon.ico”, host: “192.168.95.100”, referrer: “http://192.168.95.100/mypage”
I put the “wrongserver” in bold, because my Local currently running is called “rightserver”. “wrongserver” is not running, yet the attempted connection with this IP is with the wrong site on my Local by Flywheel.
Otherwise, I think I am very close.
I know it is OK to have more than one site on Local, especially if only one is running…is there anything I can do to make sure that the IP goes to the correct, currently running site? Obviously adding a port number doesn’t seem to work either - I tried adding 4004 as port number, but had ERR_CONNECTION_REFUSED…
2 things here:
1 - Maybe it is possible to get an IP that points to the currently running site, and not any other on Local by Flywheel
2 - I have a suspicion, that I might have to edit a hosts file on the Android Emulator itself, and so far, I haven’t found a way to do it. Android treats the emulator as if it was a real device, and the system files are protected in a way that makes it close to impossible to edit.
I hope #1 is possible, but if #2 is my only chance, at least I know which IP address to use, thanks to you.
Thank you again, and let me know if you have any particular insight on the subject. I think to be able to connect to Android Emulator, would be a great feature for Local by Flywheel…(especially since it connects so well to iOS)
Martine
There isn’t any way to get things to work like this since Local has one container that acts as a domain resolver, pointing a domain to the specific port of the VirtualMachine.
Your hunch is right, you’ll have the edit that hosts file. The only other possibility is if you can somehow get a hold of the name servers that the emulator is querying to get the domain.
Glad we were able to get things moving along for you. Let us know if you do get it working!
Hi friends of Support at Flywheel!
After a lot of work, and searching, I finally figured out how to connect my Android Emulator to my Wordpress site on Local at Flywheel…
So, I thought I’d share it with you, because there is very little information out there, and it is something that can come in very handy.
I am on a mac, so the instructions here are for the mac, even though I know it can be done on Windows or Ubuntu.
1 - In Android Studio, go to Tools/AVD Manager.
2 - Extend the list that comes up, so you can see what is in the “Target” column
3 - Choose the most recent AVD possible, and make sure the Target column says: (Google APIs) and not (Google Play).
If you don’t have any Google API targets, you can download them through the SDK Manager, SDK Tools tab, and make sure the following boxes are checked:
4 - Then, from a terminal shell, make sure that adb is in your path. It is in Users//platform-tools (on Mac).
5 - Then, locate the Android SDK tools /Users//Library/Android/sdk/tools (also on Mac)
6 - Find out the official name of the emulator you have chosen by calling:
/Users//Library/Android/sdk/tools/emulator -list-avds
7 - Launch the emulator from a terminal shell, with writable system:
/Users//Library/Android/sdk/tools/emulator -avd Nexus_S_API_25 -writable-system -memory 1024
The avd name is for example.
8 - The emulator should launch. If you get a black screen, go back to the AVD manage, press on the down arrow next to the edit pencil, and choose “Wipe Data”. Then quit the emulator, and try again.
9 - Once the emulator is running, you will need to open another terminal shell, as the emulator call does not return until you quit.
10 - From that new shell, find out the name of your current emulator instance, by calling $ adb devices
The number will usually be emulator-5554
11 - Get the “hosts” file: $ adb pull /system/etc/hosts hosts_new // This will copy the hosts file to the directory you are calling from
12 - Edit the “hosts_new” file:
Nice! Way to stick with it and figure out how to do it!
Adding what comes after #12 : ) (Edit the “hosts_new” file:)
127.0.0.1 localhost
::1 localhost
Local by Flywheel - Start
192.168.95.100 .local #Local Site
192.168.95.100 www..local #Local Site
Local by Flywheel - End
13 - Replace the original hosts file with the new one, by typing this into the “new” terminal:
$ adb root && adb -s emulator-5554 remount && adb -s emulator-5554 push hosts_new /system/etc/hosts
This “magic formula” : ), roots the emulator, makes it writable, and pushes the new file to replace the old one.
Also, if you do all this inside of the Android Studio console, you can actually connect to the debugger as well…
I am have not emulator -avd Nexus_S_API_25 -writable-system -memory 1024;Unable to proceed to the next step;What do I need to do?