xref: /aosp_15_r20/external/robolectric/scripts/README.md (revision e6ba16074e6af37d123cb567d575f496bf0a58ee)
1*e6ba1607SAndroid Build Coastguard Worker# Robolectric build-android.sh tutorial
2*e6ba1607SAndroid Build Coastguard Worker
3*e6ba1607SAndroid Build Coastguard Worker**Note:** Based on [Android documentation](https://source.android.com/source/downloading.html).
4*e6ba1607SAndroid Build Coastguard Worker
5*e6ba1607SAndroid Build Coastguard WorkerThis 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*e6ba1607SAndroid Build Coastguard Worker
7*e6ba1607SAndroid Build Coastguard Worker## 1. Installing Repo
8*e6ba1607SAndroid Build Coastguard WorkerRepo 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*e6ba1607SAndroid Build Coastguard Worker
10*e6ba1607SAndroid Build Coastguard WorkerTo install Repo make sure you have a bin/ directory in your home directory and that it is included in your path:
11*e6ba1607SAndroid Build Coastguard Worker```
12*e6ba1607SAndroid Build Coastguard Worker$ mkdir ~/bin
13*e6ba1607SAndroid Build Coastguard Worker$ PATH=~/bin:$PATH
14*e6ba1607SAndroid Build Coastguard Worker```
15*e6ba1607SAndroid Build Coastguard Worker
16*e6ba1607SAndroid Build Coastguard WorkerDownload the Repo tool and ensure that it is executable:
17*e6ba1607SAndroid Build Coastguard Worker```
18*e6ba1607SAndroid Build Coastguard Worker$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
19*e6ba1607SAndroid Build Coastguard Worker$ chmod a+x ~/bin/repo
20*e6ba1607SAndroid Build Coastguard Worker```
21*e6ba1607SAndroid Build Coastguard Worker
22*e6ba1607SAndroid Build Coastguard Worker## 2. Initializing a Repo client
23*e6ba1607SAndroid Build Coastguard WorkerAfter installing Repo, set up your client to access the Android source repository:
24*e6ba1607SAndroid Build Coastguard Worker
25*e6ba1607SAndroid Build Coastguard WorkerCreate 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*e6ba1607SAndroid Build Coastguard Worker```
27*e6ba1607SAndroid Build Coastguard Worker$ mkdir <WORKING_DIRECTORY>
28*e6ba1607SAndroid Build Coastguard Worker$ cd <WORKING_DIRECTORY>
29*e6ba1607SAndroid Build Coastguard Worker```
30*e6ba1607SAndroid Build Coastguard Worker
31*e6ba1607SAndroid Build Coastguard WorkerConfigure 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*e6ba1607SAndroid Build Coastguard Worker```
33*e6ba1607SAndroid Build Coastguard Worker$ git config --global user.name "Your Name"
34*e6ba1607SAndroid Build Coastguard Worker$ git config --global user.email "[email protected]"
35*e6ba1607SAndroid Build Coastguard Worker```
36*e6ba1607SAndroid Build Coastguard Worker
37*e6ba1607SAndroid Build Coastguard Worker## 3. Grab dependencies
38*e6ba1607SAndroid Build Coastguard WorkerOn Ubuntu run
39*e6ba1607SAndroid Build Coastguard Worker```
40*e6ba1607SAndroid Build Coastguard Worker$ sudo apt-get install git-core gnupg gnupg-agent flex bison gperf build-essential \
41*e6ba1607SAndroid Build Coastguard Workerzip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
42*e6ba1607SAndroid Build Coastguard Workerlib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
43*e6ba1607SAndroid Build Coastguard Workerlibgl1-mesa-dev libxml2-utils xsltproc unzip libswitch-perl
44*e6ba1607SAndroid Build Coastguard Worker```
45*e6ba1607SAndroid Build Coastguard Worker
46*e6ba1607SAndroid Build Coastguard Worker## 4. Run sync-android.sh to sync and build source
47*e6ba1607SAndroid Build Coastguard WorkerNow use repo to sync the android source, and then build.
48*e6ba1607SAndroid Build Coastguard Worker
49*e6ba1607SAndroid Build Coastguard Worker```
50*e6ba1607SAndroid Build Coastguard Worker./sync-android.sh <root source location> <android version> <# parallel jobs>
51*e6ba1607SAndroid Build Coastguard Worker```
52*e6ba1607SAndroid Build Coastguard Worker
53*e6ba1607SAndroid Build Coastguard WorkerThe currently supported Android versions are:
54*e6ba1607SAndroid Build Coastguard Worker
55*e6ba1607SAndroid Build Coastguard Worker*  `5.0.2_r3`    - Lollipop API 21
56*e6ba1607SAndroid Build Coastguard Worker*  `5.1.1_r9`    - Lollipop MR1 API 22
57*e6ba1607SAndroid Build Coastguard Worker*  `6.0.1_r3`    - Marshmallow API 23
58*e6ba1607SAndroid Build Coastguard Worker*  `7.0.0_r1`    - Nougat API 24
59*e6ba1607SAndroid Build Coastguard Worker*  `7.1.0_r7`    - Nougat MR1 API 25
60*e6ba1607SAndroid Build Coastguard Worker*  `8.0.0_r4`    - Oreo API 26
61*e6ba1607SAndroid Build Coastguard Worker*  `8.1.0`       - Oreo MR1 API 27
62*e6ba1607SAndroid Build Coastguard Worker*  `9`           - P API 28
63*e6ba1607SAndroid Build Coastguard Worker*  `10`          - Q API 29
64*e6ba1607SAndroid Build Coastguard Worker*  `11`          - R API 30
65*e6ba1607SAndroid Build Coastguard Worker*  `12`          - S API 31
66*e6ba1607SAndroid Build Coastguard Worker*  `12.1`        - S V2 API 32
67*e6ba1607SAndroid Build Coastguard Worker*  `13`          - T API 33
68*e6ba1607SAndroid Build Coastguard Worker*  `14`          - U API 34
69*e6ba1607SAndroid Build Coastguard Worker
70*e6ba1607SAndroid Build Coastguard WorkerBeware it can take upwards of 100 GB of space to sync and build.
71*e6ba1607SAndroid Build Coastguard Worker
72*e6ba1607SAndroid Build Coastguard WorkerFor more infomation see [Downloading and Building](https://source.android.com/source/requirements)
73*e6ba1607SAndroid Build Coastguard Worker
74*e6ba1607SAndroid Build Coastguard WorkerChoose a <# parallel jobs> value roughly equal to # of free cores on your machine. YMMV.
75*e6ba1607SAndroid Build Coastguard Worker
76*e6ba1607SAndroid Build Coastguard Worker
77*e6ba1607SAndroid Build Coastguard Worker## 7. Run build-android.sh
78*e6ba1607SAndroid Build Coastguard Worker
79*e6ba1607SAndroid Build Coastguard WorkerSigning Artifacts:
80*e6ba1607SAndroid Build Coastguard WorkerThe 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*e6ba1607SAndroid Build Coastguard Worker
82*e6ba1607SAndroid Build Coastguard Worker(Optional) You will be prompted a total of 4 times (once for each artifact). To make this easier, run this command beforehand:
83*e6ba1607SAndroid Build Coastguard Worker```
84*e6ba1607SAndroid Build Coastguard Worker$ gpg-agent --daemon
85*e6ba1607SAndroid Build Coastguard Worker```
86*e6ba1607SAndroid Build Coastguard Worker
87*e6ba1607SAndroid Build Coastguard WorkerFinally, in your Robolectric directory run:
88*e6ba1607SAndroid Build Coastguard Worker```
89*e6ba1607SAndroid Build Coastguard Worker$ export SIGNING_PASSWORD=<Passphrase for GPG signing key>
90*e6ba1607SAndroid Build Coastguard Worker$ build-android.sh <Path to AOSP source directory> <android version> <robolectric sub-version>
91*e6ba1607SAndroid Build Coastguard Worker```
92*e6ba1607SAndroid Build Coastguard Worker
93*e6ba1607SAndroid Build Coastguard WorkerFor Robolectric version `6.0.1_r3-robolectric-0`, android version would be `6.0.1_r3` and  robolectric sub-version `0`.
94