In this guide I will show how to set up a Linux guest OS for Android development.
Basic Linux usage.
Basic Android Studio usage.
Android Device – If you want to learn how to run your app on a device and not emulator. I’m using a Sony z1.
Around 30 min.
Table of content
- Step 0 – Xubuntu
- Step 1 – Why is my screen so small?!
- Step 2 – Android Studio
- Step 3 – Android Project
- Step 4 -Troubleshooting
Android is based on Linux and most tools for developing is made for Linux. I used to develop using Windows but it was never as smooth as for Linux. Sometimes my work has forced me to use a Windows machine and then the first thing I do is to install a linux VM. I really hate to use Cygwin – why try imitate Linux when you can have the real thing?
Now using virtualbox for Android isn’t totally pain free since you need to use adb through USB, something that can be tricky to set up correctly, especially if your host is Linux.
Step 0 – Xubuntu
When I first started to use Ubuntu I loved it. It was not full of things I didn’t need as in Windows and it was quite user friendly. However, after a while I started to feel it was bloated and I never liked Unity. Unity throws big icons in my face and more than a few times it is incompatible and you have to do a lot of research to solve the problems.
If you are going to use your VM for Android development I instead recommend Xubuntu. It is very similar to Ubuntu, but it is stripped down and the desktop environment xfce is much more in my taste.
In this guide I will be using Xubuntu, but it should be fine to use any Ubuntu clone.
Download and install Xubuntu here:
In this guide I’m using Xubuntu 14.04 64-bit. First thing to do is to is to update the guest OS. Note that for this guide ‘$’ means normal shell command, while ‘#’ means executed as super user.
Step 1 – Why is my screen so small?!
This is probably everyone’s first question when they have installed a Linux guest.
Pressing [right ctrl + f] enter full screen mode, but still the working area is 800×600. You need to install the guest additions to get a higher resolution. The good news is that for Ubuntu it is easy (while it is somewhat more demanding for other distros such as CentOS).
Install the guest addition for x11 and reboot:
#apt-get install virtualbox-guest-x11
Ah, that’s better!
Step 2 – Android Studio
Android Studio requires Java, and of course if you are going to develop for android you need Java 7+. Xubuntu doesn’t come with java so you have to install:
#apt-get install oracle-java8-installer
Check the configuration with:
Download Android Studio:
Make sure you choose “All Android Packages” and not “SDK tools only”. In this guide I have used android-studio-ide-141.1980579-linux.zip.
Extract the archive. I extracted it to ~/android/android-studio
If you have 64-bit version of your guest, then you will have to install some 32-but libraries to be able to run Android Studio.
#apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
Start android studio:
I found Darcula them doesn’t look good in Xubuntu so I choose the default IntelliJ.
You will have to download the SDK. At some of my positions we had our own SDK but I haven’t found a way to skip this step. I installed it to ~/android/sdk
Step 3 – Android Project
Create a new Android Project with a blank activity. Connect your Android Device with USB. Run the app [shift F10]
The Choose Device dialog is empty.
Check the status of the USB on the guest:
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 80ee:0021 VirtualBox USB Tablet
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Hmm… there’s no USB device connected. Try to run the same command on your host if you run Linux, or check “This PC” if you use windows. The USB is visible at the host right?
To allow the guest to detect USB you need to add it to the VM USB Device Filters.
Open virtualbox and click USB and then on the USB with a green plus sign. You should see your device in this list. Select it and make sure it is checked and then press OK.
Only one OS (host or guest) can control an USB device at the same time. This is important to remember when you troubleshot your USB. The Device Filter control if the guest OS should use the USB or the host.
Disconnect the USB and reconnect it and check for devices on your guest.
Bus 001 Device 004: ID 0fce:d107 Sony Ericsson Mobile Communications AB
Don’t forget to check the “USB debugging” in developers option of the Android Device.
Step 4 -Troubleshooting
I use Linux and I can’t see my USB device:
You need to add yourself to vboxusers group, or you wont have permission to access the USB devices.
#adduser $USER vboxusers
I can find my device but not use it in Android studio:
Make sure USB debugging is on on the android device.
adb devices shows ?????? as id:
adb does not have the correct premissions. Try to restart it as super user:
Setting up an Android development environment on a guest is quite same as on a host. The only thing you need to consider is the USB support. Your key tools when trouble shooting is lsusb and adb. adb devices gives you information about the android device, while lsusb gives you information about USB devices.
I prefer Xubuntu, but if you want a really easy installation I recommend Linux mint http://www.linuxmint.com/download.php. It automatically installs the guest drivers (and cinnamon looks damn good). Cooperates should really consider using mint instead of Ubuntu.