Build AOSP(Android 11 beta 1) on Ubuntu 20.04(Focal Fossa)
The instructions we find on the Establishing a Build Environment work only on Ubuntu 14.04 and older Ubuntu versions. To build the AOSP on latest Ubuntu version(Ubuntu 20.04 Focal Fossa at the time of this writing), we need to install some additional dependencies to avoid problems such as:
/usr/bin/env: ‘python’: No such file or directory
OR
error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
At the time of writing this article, the Android 11 beta 1 was on master
branch. So, we will be building the AOSP master
branch which has Android 11 beta 1 source code, on the Ubuntu 20.04 system. Let us get started.
Install the dependencies using following command:
sudo apt-get install openjdk-8-jdk android-tools-adb bc bison build-essential curl flex g++-multilib gcc-multilib gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-gtk3-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc yasm zip zlib1g-dev git-core python3.8 libncurses5
After the dependencies are installed successfully, configure the user’s name and email for git
with following commands:
git config --global user.name "Firstname Lastname"
git config --global user.email "user@email.address"
Download the repo
client and put it in the executable path with following commands:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
At this point executing repo init -u https://android.googlesource.com/platform/manifest
command gives following error:
/usr/bin/env: ‘python’: No such file or directory
Ubuntu 20.04 comes with python3
out of the box. When installing the dependencies, we installed python3.8
. To use this version of python
, and still have option to use any other version of python, my preferred method is to use update-alternatives
. Use the following set of commands to link python
command to python3.8
.
sudo update-alternatives --install /bin/python python /usr/bin/python3 1
sudo update-alternatives --install /bin/python python /usr/bin/python3.8 2
sudo update-alternatives --config python
Select the number associated with python3.8
(2 in this case) here.
At this point code can be downloaded using following commands:
repo init -u https://android.googlesource.com/platform/manifest
repo sync -cdj16 --no-tags
Finally start the build using:
source build/envsetup.sh
lunch lunch aosp_x86-userdebug
make -j16
Build should succeed at this point.
All commands at one glance:
sudo apt-get install openjdk-8-jdk android-tools-adb bc bison build-essential curl flex g++-multilib gcc-multilib gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-gtk3-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc yasm zip zlib1g-dev git-core python3.8 libncurses5git config --global user.name "Firstname Lastname"
git config --global user.email "user@email.address"mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/reposudo update-alternatives --install /bin/python python /usr/bin/python3 1
sudo update-alternatives --install /bin/python python /usr/bin/python3.8 2
sudo update-alternatives --config python # Select 2 hererepo init -u https://android.googlesource.com/platform/manifest
repo sync -cdj16 --no-tagssource build/envsetup.sh
lunch lunch aosp_x86-userdebug
make -j16