This guide aims to teach users about the basics of android building. If you want to build A12+ for devices not using linux 4.4 and up please refer to Building android for legacy devices For versions unsupported by AOSP refer to Building Legacy Android
Do not follow this guide inside Crave Devspace CLI, follow this instead because this guide shows things that are against Devspace Rules
repo
Repo is a tool developed by google to help manage the thousands of git repos used in a project like AOSP.
You must first install it on your computer/server.
mkdir ~/bin && curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo
After that you should check if ~/bin is already in your PATH by doing
printenv PATH|grep ~/bin
if you do not get any output you have to add:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
to ~/.profile or some other script that runs on shell creation.
There are also some additional dependencies, which you need to install to build android.
Arch Linux:
sudo pacman -S repo base-devel git-lfs
Debian / Ubuntu based distros:
sudo apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git git-lfs gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-gtk3-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev
Fedora / Fedora based distros:
sudo dnf install @development-tools android-tools automake bison bzip2 bzip2-libs ccache curl dpkg-dev flex gcc gcc-c++ git git-lfs glibc-devel.{x86_64,i686} gperf libstdc++.{x86_64,i686} libxcrypt-compat libxml2-devel libxslt lz4-libs lzop make maven ncurses ncurses-compat-libs ncurses-devel.{x86_64,i686} openssl openssl-devel pngcrush python python3-virtualenv python3 python3-mako python-mako python-networkx schedtool squashfs-tools syslinux-devel unzip zip zlib zlib-devel
You might need to remove metadata_csum_seed and orhpan_file from /etc/mke2fs.conf if you encounter error mentioning "Invalid filesystem option set" as per Reddit
If you build a lot you should consider enabling ccache to save yourself some build time.
export USE_CCACHE=1
export CCACHE_EXEC=/usr/bin/ccache
You should limit its size to something reasonable with the below command
ccache -M 50G
To further increase the number of cached files at the cost of slight decompression overhead you can enable compression.
ccache -o compression=true
mkdir Lineage
cd Lineage
repo init -u https://github.com/LineageOS/android.git -b lineage-21.0 --git-lfs
Replace the url with the link to your preferred source of android. Replace the branch with the version of android you want to build. (Lineage 21 is A14, 20 is A13)repo does not know who you are
git config --global user.name "ProAndroidBuilder" # This can be any name, even your real name.
git config --global user.email "android@veryrealemail.com" # This should be your email.
Be warned, these info will be public if you start committing and pushing things. --depth=1
repo sync -c --force-sync --optimized-fetch --no-tags --no-clone-bundle --prune -j$(nproc --all) --retry-fetches=25
In case you get RPC errors, try reducing the -j argument to something like four. I usually run this sync command two or three times, to clone any repos that failed to clone during the previous sync (bad internet problems).
Excellent! You have now successfully cloned android!
In order to build android for a device, you must first clone a few things:
The exact repos to clone varies from device to device. Some devices may use a common tree (which means that you have to clone 2 device and vendor trees), while others (especially samsung trees) have many hardware/ dependencies.
Sometimes, the device maintainer might have been kind enough to share a "local manifest". This basically allows you to clone the trees hassle-free with
repo
If you are lucky enough to have a local manifest, just drop it in to
ANDROID_CLONE_DIRECTORY/.repo/local_manifests/
(you may have to create this directory). After this, just run repo sync once more. You can also do this step right after repo init to save yourself another sync.
If you arent lucky enough to have a local manifest, do not worry, you can still clone the repos manually.
Run
git clone https://url -b branch(optional) path/to/folder
Vendor repos are usually not listed, but try to get them from the same source as the device trees. For official Lineage OS this TheMuppets GitLab/GitHub, but you can also extract the blobs manually if you have a build with that tree flashed onto your device by running:
./extract-files.sh
or
./extract-files.py
in your device tree when connected to your device with enabled adb root. Alternatively you can also extract them from the rom zip
Note: Most people name their android-related repositories like
android_device_xiaomi_spes
device_xiaomi_spes
_
/
. build/envsetup.sh
or
source build/envsetup.sh
lunch PRODUCT-RELEASE(IF A14 QPR2+)-VARIANT
However, it is easier to use breakfast instead, like
breakfast PRODUCT VARIANT
release
ap1a
main
trunk_staging
ls -1 -I trunk_staging -I root $(gettop)/build/release/aconfig/ | tail -n1
eng
userdebug
eng
user
user
adb root
user
m -j$(nproc --all)
m bacon -j$(nproc --all)
Hopefully, android builds without errors. This guide does not cover fixing common errors. Once done, you should hopefully see
build completed
The built rom is stored in
out/target/product/YOUR DEVICE CODENAME
Depending on which target you chose, the files here will be different. Simply share your *.img files or the latest .zip file in that folder. Please ensure to have your build(s) thoroughly tested before you publicly release them.
If your rom does not boot, ask other maintainers for your device if your device needs specific patches or refer to Debugging in order to grab logs.