Developing Android Apps, right on your Chromebook
Since last year announcement of the Play Store coming to Chromebooks, and more generally devices running Chrome OS, the Linux-powered operating system by Google, most of these devices have gradually received the update and can now benefit from millions of compatible apps.
Officially, it has been made possible to develop for a Chromebook using ADB, over the network, just like a regular Android device.
What if one could directly use Android Studio on the Chromebook, and see the app natively popping up on the same device, without the need of any kind of emulator or external device? It would make a lot of sense away from home, with a Chromebook as only companion.
As a matter of fact, this very scenario is perfectly achievable using a slick piece of technology, the crouton script, which allows to install components of some Linux distributions, right inside Chrome OS — no need for dual-booting here. Using crouton, one can launch most of Linux applications inside a Chrome OS window, Android Studio included. The second thing we need is the Developer Mode enabled on the device, so that we can install this script and then, locally connect Android Studio to the Android Runtime.
Let’s get started.
Turn on Developer Mode: will wipe all data ⚠️
Visit this page, click on your model and follow the instructions (make sure to backup your files before, all your data will be lost).
Install the crouton extension
Head over to the Chrome Web Store and install this extension.
Create a Linux chroot with crouton
Following the easy way, with some slight changes, you can get it up quickly:
- Download crouton on your Chromebook (should be in your Downloads folder)
- Open the Chrome terminal with Ctrl+Alt+T
- Enter the shell by typing
sudo sh ~/Downloads/crouton -t xfce,extension,xorg,xiwi
It may take a while, since it’s going to fetch all the required packages online and install them. For the record, on my Acer R11 it took about 30 minutes (5Mbps Internet connection, yes this is still a thing in 2017).
In the meantime, let me explain what we did with the last command, which actually differs a bit form the one written in the easy way. By default, Ubuntu 16.04 LTS is installed, which is totally fine for our purpose. xfce is the desktop environment that will be used (not mandatory, but handy for the next step, plus you may need it for other Linux-related things). The target extension will bring clipboard synchronization and some other integrations between the chroot and Chrome OS. xorg,xiwi means that the script will install two different ways to access the chroot: either with the default xorg server (using a combination of keys to go back and forth between the chroot’s desktop and Chrome’s), or directly inside a Chrome OS window or tab. We’ll use the first to setup Android Studio, and then the latter to launch it as an independent window.
You’ll be prompted to create a Linux username and password. Remember it.
Download Android Studio for Linux
You can leave it as a .zip inside your Downloads folder.
Setup Android Studio in your chroot
Go back to the terminal (or fire it up again with Ctrl+Alt+Tab and typing
sudo startxfce4 and enter your sudo password.
Theorically after a bunch of logs the XFCE desktop should start. You can go back and forth between XFCE and Chrome OS at any time using
Ctrl+Alt+Shift+Forward . To shut down the chroot, just logout from XFCE.
Choose the default config and open the File Manager (there’s a Home shortcut on the desktop).
Head over to ~/Downloads (same as your Chrome OS folder), right click on your android-studio-*.zip file and select Extract Here.
You can either leave the extracted android-studio here in ~/Downloads, or move it somewhere else, like a new ~/Software folder. Just remember it.
Go to ~/Software/android-studio/bin, and open a terminal here (right click inside the folder, Open Terminal Here).
sh studio.sh and go through the configuration of Android Studio (you can choose to install the SDK to an external storage like a SD card if you’re short in disk space). You don’t need to install any virtual device. Downloading and installation take some time.
Then start a new empty project, so that we can access the main window.
Once there, click on Tools > Create Command-line Launcher. The suggested location should be fine by default (/usr/local/bin/studio). Press OK and close Android Studio.
Go back to the chroot terminal (Ctrl+Alt+T works too), make sure python is installed, so that the shortcut that Android Studio has just created works:
sudo apt install python
You can try to run
studio. Android Studio should start inside the chroot.
If you don’t use a QWERTY keyboard, and want another layout to be use with the standalone Android Studio window that we will create, you can create a ~/.xiwirc file, containing a command that will be executed at xiwi startup:
setxkbmap [layout] [variant]
For instance, to use the Bépo variant of the French keyboard layout:
setxkbmap fr bepo. Find yours here.
You can now logout of XFCE.
Launch Android Studio as a Chrome window
Go back to the Chrome terminal (or fire it up again with Ctrl+Alt+Tab and typing
sudo enter-chroot xiwi studio: Android Studio should start on your Chrome OS desktop, after a bunch of logs (and probably some errors about the crouton extension). Leave it open.
Make the Chromebook show up as an ADB device
Go back to the Chrome terminal (Ctrl+Alt+Tab then
Run the following commands, one by one. This will configure the firewall for our needs (just like the official instructions are stating).
sudo crossystem dev_boot_signed_only=0
Your computer should reboot. Don’t forget Ctrl+D at startup.
Then open a Chrome terminal (Ctrl+Alt+T then
shell) and run:
Now, we need to enable ADB Debugging from the Android settings of the Chromebook (quoting the official instructions):
- Click the clock icon in the bottom-right area of the screen.
- Click Settings.
- In the Android Apps section, click the Settings link in the line that reads Manage your Android apps in Settings. This brings up the Android apps settings.
- Click About device.
- Click Build number seven times to move into Developer mode.
- Click the arrow in the top-left area of the window to go back to the main Settings screen.
- Click the new Developer options item, activate ADB debugging, and then click OK to allow ADB debugging.
Finally, we can go back to our Chrome terminal (Ctrl+Alt+T then
shell) and run:
adb connect localhost:22 (we’re using the default ssh port here).
A dialog should popup asking if you would like to allow ADB to control the Android side, ticking the Always allow for this computer box is a good idea, and press OK.
You should get a confirmation that it worked: connected to localhost:22
If not, something must be wrong in your firewall settings, go back to this section.
Run your app
Now it’s time to start Android Studio (
sudo enter-chroot xiwi studio in a Chrome terminal), open the project you want (our empty one for instance), hit the Run button, choose your Chromebook and enjoy the view.
In case your Chromebook doesn’t appear in the target list, open another Chrome terminal (Ctrl+Alt+T then
shell) and restart the ADB connection:
adb connect localhost:22
Side note: if you open the Android Studio Terminal, you’ll have a bash session from the Ubuntu chroot. So you can easily install and use developer tools such as git (
sudo apt install git).
Optional: make an alias for the Android Studio startup command
If you’re as lazy as me, you’ll think than typing more than 10 characters is way too much (especially the dash thing). Let’s create an alias of our Android Studio startup command, for instance it would be nice only having to type
studio instead of
sudo enter-chroot xiwi studio.
To achieve this, fire up a Chrome terminal once again (Ctrl+Alt+T then
shell) and run the following command. You’ll have to open a new Chrome terminal to apply the change.
echo 'alias studio="sudo enter-chroot xiwi studio"' >> ~/.bashrc
I’ve been looking for a way to create a desktop shortcut for Android Studio, instead of launching it with the terminal, but I haven’t found any simple solution yet. I’ll update this post if anything satisfying comes up.
EDIT (11 Feb 2018)
Highlighted by Nolirium on a blog article, there is a solution to pin shortcuts on the Chrome OS shelf for xiwi apps. Check it out! You can directly jump to Section 3. (b).
Clearly it isn’t that complicated to extend the relevance of a Chromebook for an Android developer. Imagine how interesting it would be for Google to have this implemented out-of-the-box (some work is apparently being done). We could finally make use off all the power that is being shipped with higher-end Chrome OS devices — I’m looking at you, Pixelbook — and it could be quite a game-changer for many potential buyers.
Running freshly compiled apps on a Chromebook can even have its advantages over a regular developer setup, such as being able to resize the app, allowing easy responsiveness testing. As well as being able to work away from home, without the hassle of RAM-hungry emulators and devices hanging around by their USB cable.