NOTES:
p1
referred to below is simply the name given to the LXC. You can change this if you want, just remember to always refer to the same container name :P- Only for real devices: make sure that the vendor ID you enter into the android udev rules file matches the device you want to be visible
-
first, set up vagrant VM to run on a "public network". My
Vagrantfile
's only network config is:config.vm.network "public_network", :bridge => 'en0: Wi-Fi (AirPort)'
-
get inside yo ubuntu vm
-
(hardware devices only) connect device and run either
lsusb
orusb-devices
- make sure your ubuntu host sees the device. -
sudo apt-get update && sudo apt-get -y dist-upgrade
-
sudo apt-get install -y linux-image-current-generic
-
reboot your ubuntu host!
-
sudo apt-get install -y lxc
-
sudo lxc-create -t ubuntu -n p1
this may take a while, beertimenao -
edit /etc/default/lxc. we want to create a weird private network so our mac can talk to the container. change a few lines so they look like this:
# Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your # containers. Set to "false" if you'll use virbr0 or another existing # bridge, or mavlan to your host's NIC. USE_LXC_BRIDGE="true" # If you change the LXC_BRIDGE to something other than lxcbr0, then # you will also need to update your /etc/lxc/lxc.conf as well as the # configuration (/var/lib/lxc/<container>/config) for any containers # already created using the default config to reflect the new bridge # name. # If you have the dnsmasq daemon installed, you'll also have to update # /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon. LXC_BRIDGE="lxcbr0" LXC_ADDR="10.0.150.1" LXC_NETMASK="255.255.255.0" LXC_NETWORK="10.0.150.0/24" LXC_DHCP_RANGE="10.0.150.2,10.0.150.254" LXC_DHCP_MAX="253"
-
edit /var/lib/lxc/p1/config and uncomment the line
#lxc.aa_profile = unconfined
-
run
ifconfig
and note downeth1
's IP: this is your VM's ip. mine is 10.0.1.136, so for all following instructions, replace my IP with yours :) -
sudo iptables -t nat -A POSTROUTING -o 10.0.1.136 -j MASQUERADE
-
we might need to add a route to 10.0.150.0 inside the vm.. im not sure.. ask Daniel! :D
-
lets quickly hop back to Mac-land. Run
route -n add 10.0.150.0/24 10.0.1.136
. So, basically, route our container IP to our VM IP. -
You should be able to ping 10.0.150.1 from mac land. If not.. ask Daniel :D
-
(hardware devices only)
sudo mkdir -p /var/lib/lxc/p1/rootfs/dev/bus/usb
-
(hardware devices only)
sudo mount --bind /dev/bus/usb /var/lib/lxc/p1/rootfs/dev/bus/usb
-
sudo lxc-start -n p1 -d
start the container in the background` -
sudo lxc-console -n p1
connect to the container, use ubuntu/ubuntu as user/pass. sudo pass inside containers is ubuntu. -
sudo apt-get update
-
sudo apt-get install -y x11vnc git vim xvfb wget unzip build-essential openjdk-6-jdk python-software-properties usbutils
a drink of your choice for getting this far! -
sudo apt-get -y install libfuse2
-
cd /tmp
-
sudo apt-get download fuse
-
sudo dpkg-deb -x fuse_* .
-
sudo dpkg-deb -e fuse_*
-
sudo rm fuse_*.deb
-
edit /tmp/DEBIAN/postinst so it looks like:
#!/bin/bash exit 0
-
sudo dpkg-deb -b . /fuse.deb
-
sudo dpkg -i /fuse.deb
-
sudo apt-get install -y ia32-libs
-
(hardware devices only) you should see your device connected! run
usb-devices
-
sudo add-apt-repository ppa:chris-lea/node.js
-
press enter
-
sudo apt-get update
-
sudo apt-get install -y nodejs
all the nodez are mine` -
sudo npm install -g appium mocha
-
cd /
-
if you have the android sdk zip on your mac, copy it to a shared folder on your vm, or
wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20131030.zip -O adt.zip
maybe a snack this time? -
unzip adt.zip -d /home/ubuntu
-
mv /home/ubuntu/adt-bundle-linux-x86_64-20131030 /home/ubuntu/adt
-
echo "export JAVA_HOME=/usr" >> ~/.bashrc
-
echo "export ANDROID_HOME=/home/ubuntu/adt/sdk" >> ~/.bashrc
-
echo "export PATH=${PATH}:/home/ubuntu/adt/sdk/tools:/home/ubuntu/adt/sdk/platform-tools" >> ~/.bashrc
-
(hardware devices only)
echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"18d1\", MODE=\"0666\", GROUP=\"plugdev\"" > /etc/udev/rules.d/51-android.rules
-
sudo chmod -R a+rwx /home/ubuntu/adt
-
(hardware devices only)
sudo chmod a+r /etc/udev/rules.d/51-android.rules
-
source ~/.bashrc
-
sudo /usr/local/adt/sdk/tools/android create avd --name 4.4 --force --target android-19
create an android 4.4 virtual device (emulator configuration) called 4.4 using the arm image. whether to use the x86 or the arm image here depends on the particular hardware running. macbooks can run the intel image. server hardware may not be able to. intel is preferred (generally faster) compared to arm. at this time android 4.4 did not have an intel img available. -
sudo /usr/local/adt/sdk/tools/emulator -avd 4.4 -noaudio -noskin -no-window -verbose -qemu -vnc :2 &
starts the emulator -
you may get errors about missing keymaps. Note down the location that the emulator is complaining it cant find the keymaps. I had to create that directory. Then, I found this random github repo with a ton of keymaps. I created/copied over the necessary files that the emulator was complaining about from there. That seemed to work. shrug
-
the emulator should be visible to
adb
, but not "online" yet, check by runningadb devices
. we can probably script something really simple that pollsadb devices
and checks until the emulator goes fromoffline
todevice
. -
double check your container's IP:
ifconfig
. It should be 10.0.150.x. -
once the emulator is no longer
offline
, go back to mac-land, open up a vnc viewer (I use Chicken of the VNC), point it to 10.0.150.x:5902, and voila! VNC!