Chrome Unboxed – The Latest Chrome OS News

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).

It should be noted that we have created a video tutorial on getting into dev mode and getting Linux via Crouton up and running. You can check that out right here.

Create a Linux chroot with

Following the easy way, with some slight changes, you can get it up quickly:

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. To benefit from it, hand over to the Chrome Web Store and install this extension.  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

Once the script has finished (you’ll see a *Done!* message), open a new tab and go to the download page (or here if you want the preview version of Android Studio 3.0, with first-class Kotlin support.)

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 shell).

Run sudo startxfce4 and enter your sudo password.

Theoretically 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+Back and 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).

Run sh and go through the configuration of Android Studio (you can choose to install the SDK to an external storage like an SD card if you’re short on 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 used 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 terminal (or fire it up again with Ctrl+Alt+Tab and typing shell).

Run 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 terminal (or fire it up again with Ctrl+Alt+Tab and typing shell).

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
sudo /usr/libexec/debugd/helpers/dev_features_rootfs_verification
sudo reboot

Your computer should reboot. Don’t forget Ctrl+D at startup.

Then open a Chrome terminal (Ctrl+Alt+T then shell) and run:
sudo /usr/libexec/debugd/helpers/dev_features_ssh

Now, we need to enable ADB Debugging from the Android settings of the Chromebook (quoting the official instructions):

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 kill-server
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 that 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.

Final Thoughts

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.

This post originally appeared on Medium