Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Android Studio in a chroot Setup

Android Studio in a chroot Setup on Debian

Install schroot, debootstrap, and the ubuntu-archive-keyring (needed for debootstrap to validate downloaded Ubuntu files):

sudo apt install schroot debootstrap ubuntu-archive-keyring

Create a clean Ubuntu 14.04 amd64 chroot using debootstrap:

sudo mkdir -pv /opt/chroot/android-studio
sudo debootstrap --arch=amd64 trusty /opt/chroot/android-studio/

Add this chroot to schroot's config file by editing /etc/schroot/schroot.conf to add the following data (replace the user name with your actual user name):

[android-studio]
description=Ubuntu 14.04 for Android Studio
directory=/opt/chroot/android-studio
type=directory
users=andrew
preserve-environment=true

Enter the chroot using schroot:

schroot -c android-studio

Inside the chroot, enable the i386 arch packages, do an apt update, and install the i386 libs that you'll need:

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

Although the Android Studio documentation fails to mention it, you will also need to install the following things in order for the studio.sh script to run correctly:

sudo apt install libxext6 libxrender1 libxtst6 libxi6 libfreetype6

Then you can download the Android Studio zip file from https://developer.android.com/studio/index.html and unzip it into your home directory like (replace filename with actual one you downloaded):

unzip downloads/android-studio-ide-171.4408382-linux.zip

Now, finally, you can run the studio.sh script from within the chroot like:

android-studio/bin/studio.sh

During the first run setup in studio.sh you can pick all the defaults. If you want to use the GTK style GUI you likely will need additional packages installed.

In order to automate entering the chroot and running Android Studio, you can create a script called android-studio in your ~/bin/ directory, and assuming that's on your PATH, then you can simply execute it. The script should be like:

#!/bin/sh
schroot -c android-studio ~/android-studio/bin/studio.sh

Make sure the permissions on the script allow you to execute it:

chmod u+x bin/android-studio

As many existing open source Android applications store their source code in the git version control system, you'll probably want git available in your chroot so that Android Studio can use it:

sudo apt install git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment