1# Robolectric build-android.sh tutorial 2 3**Note:** Based on [Android documentation](https://source.android.com/source/downloading.html). 4 5This tutorial will allow you to run the `build-android.sh` script in the Robolectric repository, resulting in the corresponding Android version's android-all jar. 6 7## 1. Installing Repo 8Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see the Developing section. 9 10To install Repo make sure you have a bin/ directory in your home directory and that it is included in your path: 11``` 12$ mkdir ~/bin 13$ PATH=~/bin:$PATH 14``` 15 16Download the Repo tool and ensure that it is executable: 17``` 18$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo 19$ chmod a+x ~/bin/repo 20``` 21 22## 2. Initializing a Repo client 23After installing Repo, set up your client to access the Android source repository: 24 25Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like: 26``` 27$ mkdir <WORKING_DIRECTORY> 28$ cd <WORKING_DIRECTORY> 29``` 30 31Configure git with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a [registered Google account](https://myaccount.google.com/?pli=1). Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions. 32``` 33$ git config --global user.name "Your Name" 34$ git config --global user.email "[email protected]" 35``` 36 37## 3. Grab dependencies 38On Ubuntu run 39``` 40$ sudo apt-get install git-core gnupg gnupg-agent flex bison gperf build-essential \ 41zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \ 42lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \ 43libgl1-mesa-dev libxml2-utils xsltproc unzip libswitch-perl 44``` 45 46## 4. Run sync-android.sh to sync and build source 47Now use repo to sync the android source, and then build. 48 49``` 50./sync-android.sh <root source location> <android version> <# parallel jobs> 51``` 52 53The currently supported Android versions are: 54 55* `5.0.2_r3` - Lollipop API 21 56* `5.1.1_r9` - Lollipop MR1 API 22 57* `6.0.1_r3` - Marshmallow API 23 58* `7.0.0_r1` - Nougat API 24 59* `7.1.0_r7` - Nougat MR1 API 25 60* `8.0.0_r4` - Oreo API 26 61* `8.1.0` - Oreo MR1 API 27 62* `9` - P API 28 63* `10` - Q API 29 64* `11` - R API 30 65* `12` - S API 31 66* `12.1` - S V2 API 32 67* `13` - T API 33 68* `14` - U API 34 69 70Beware it can take upwards of 100 GB of space to sync and build. 71 72For more infomation see [Downloading and Building](https://source.android.com/source/requirements) 73 74Choose a <# parallel jobs> value roughly equal to # of free cores on your machine. YMMV. 75 76 77## 7. Run build-android.sh 78 79Signing Artifacts: 80The end of the script will prompt you to sign the new artifacts using GPG. See [Performing a Release](https://github.com/robolectric/robolectric-gradle-plugin/wiki/Performing-a-Release) for instructions on obtaining a GPG key pair. 81 82(Optional) You will be prompted a total of 4 times (once for each artifact). To make this easier, run this command beforehand: 83``` 84$ gpg-agent --daemon 85``` 86 87Finally, in your Robolectric directory run: 88``` 89$ export SIGNING_PASSWORD=<Passphrase for GPG signing key> 90$ build-android.sh <Path to AOSP source directory> <android version> <robolectric sub-version> 91``` 92 93For Robolectric version `6.0.1_r3-robolectric-0`, android version would be `6.0.1_r3` and robolectric sub-version `0`. 94