How to run Android Studio on a Chromebook with 4GB of RAM

It is not a secret that Android Studio could almost perfectly run on a PC with 4GB RAM if we are talking about Windows OS or Linux. Yes, we already have an official Android Studio build for Chrome OS, but things are not so simple here.

The main reason why you could have problems running Android Studio on a Chrome OS with 4GB of RAM is that Android Studio is a Linux application, so it would run on Chrome OS inside a Crostini virtual environment. And virtual environment means that you don’t have direct access to all your hardware resources. Your RAM is not an exception. Free RAM for Crostini is restricted and controlled by Chrome OS.

My own experience with Crostini ends up building a Flutter application. I mean Android Studio runs almost perfectly until you’ll run an app with a debugger attached. Sometimes it even starts an app on a connected Android device and can handle debug messages for 10 seconds, but most of the time build fails with the unexpected disappearance of Gradle daemon or even Android Studio hangs or crashes.

Actually, it is not a surprise because the official requirements for running Android Studio on Chrome OS contains “8GB of RAM minimum”.

This issue can be solved in different ways. You can buy a new Chromebook with 8GB of RAM. You can write code in Caret and run it with command line tools. Or you can use Crouton.

Crouton is a set of scripts and tools to generate chroot environments. It allows you to run Ubuntu or Debian in parallel with Chrome OS. The main difference with Crostini is that you will have direct access to all your hardware resources. And yes, it will allow you to run Android Studio having just 4GB of RAM.

The simplest way to start is to set up the default chroot with Ubuntu 16.04 and Xfce desktop environment.

It is required to put your Chromebook in Developer Mode. Doing this will erase all user data.

If your Chromebook is already in Developer Mode, next you need to

  1. Download Crouton installer. It is the first link on Crouton github page right in repository description. Put it to your Downloads folder.
  2. Open Chrome OS developer shell with Ctrl+Alt+t and execute shell command there:
crosh> shell
chronos@localhost / $
  1. Make Crouton installer a system executable with:
sudo install -Dt /usr/local/bin -m 755 ~/Downloads/crouton
  1. Create your first chroot:
sudo crouton -t xfce

and wait for installation to finish.

This is almost all. Actually, you already can run a Linux environment, but let’s install some additional components with this command:

sudo crouton -u -t extension -n xenial

It will add an extension component to your chroot. You need it to synchronize the clipboard between Chrome OS and Ubuntu and some other useful things. You also need to install the crouton integration Chrome extension.

This is it. Now you can start Ubuntu with:

sudo startxfce4

Use Ctrl+Alt+Shift+Back and Ctrl+Alt+Shift+Forward to switch between Ubuntu and Chrome OS.

{% include ads_media.html %}

Set up Android Studio

By default your Downloads folder of Chrome OS is mounted to ~/Downloads in your chroot, so basically you have the same Downloads folder in Chrome OS and Ubuntu. This will make things easier.

  1. Download Android Studio for Linux (not Chrome OS) from the download options page of developer.android.com and save it to your Downloads folder.
  2. Switch to Ubuntu with Ctrl+Alt+Shift+Forward, launch the File Manager app, and simply extract the Android Studio archive from the Downloads folder to any location inside your home folder. I’m using the ~/bin folder.
  3. After that, you will be able to start Android Studio in your Ubuntu by executing
~/bin/android-studio/bin/studio.sh

in Terminal app. 4. You also can edit your .bashrc file in the home directory of Ubuntu and add an alias for this command. Use the File Manager app to open your home directory (It is /home/[your_username]), make hidden files visible with Ctrl+h, and double-click the .bashrc file to open it in the default editor. Now just add this line to the end of the file:

alias 'android-studio'='~/bin/android-studio/bin/studio.sh'

From now on you can just execute the android-studio command in the terminal of Ubuntu to start Android Studio.

Some notes

If you don’t want to lose your data, you need to properly exit Android Studio, then Log Out from Ubuntu and wait for chroot to stop in Chrome OS shell. You need to see something like this:

Unmounting /mnt/stateful_partition/crouton/chroots/xenial…
Sending SIGTERM to processes under /mnt/stateful_partition/crouton/chroots/xenial…
chronos@localhost / $

Only after that you can send your Chromebook to sleep or turn it off. It is not recommended to go to sleep with launched chroot.

Note that sometimes when the free RAM of your system comes to the end, browser tabs of Chrome OS will be unloaded from memory. As Chrome OS shell also runs inside the browser tab it can be also unloaded to free some memory. In that case, you will see a new crosh session in that tab instead of your chroot environment output. Just use git for your code and push often and your data will be safe.

There is a possibility to run any app from your chroot environment in a standalone window right in your Chrome OS, without even starting Xfce. Just don’t use it for Android Studio! There are a number of known issues that will be not resolved in nearest future: code hints with Ctrl+Space and clipboard sync will be broken for example.


Posted

in

, ,

Follow the updates:

Comments