Use apt to install the following tools
sudo apt upgrade
sudo apt update
sudo apt install -y \
vim \
git-core \
gnupg \
flex \
bison \
gperf \
build-essential \
zip \
unzip \
curl \
zlib1g-dev \
gcc-multilib \
g++-multilib \
libc6-dev-i386 \
lib32ncurses5-dev \
x11proto-core-dev \
libx11-dev \
lib32z-dev \
ccache \
libgl1-mesa-dev \
libxml2-utils xsltproc \
libncurses5 \
libelf-dev \
libswitch-perl
Install Google's repo tool to download Android source code and Android kernel code
Download and install the repo tool
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Download Source Code#
mkdir android_source && cd android_source
Make sure to set up basic git information, name, email
git config --global user.name <Your Name>
git config --global user.email <you@example.com>
repo init: specify the url & branch you want to download (branch name can refer to the official documentation)
repo init -u https://android.googlesource.com/platform/manifest \
-b android-13.0.0_r1
repo sync
Compile Android#
Initialize the environment: run the following command in the root folder of the downloaded Android
cd ~/android_source
source ./build/envsetup.sh
lunch select build target: choose the target to compile, the format consists of BUILD, BUILDTYPE
Build refers to the platform to run after compilation
BUILD | Target Device | Notes |
---|---|---|
Full | Emulator | Full compilation, includes all languages, apps, input methods, etc. |
full_manguro | manguro | Full compilation, runs on Galaxy Nexus GSM/HSPA+("manguro") |
full_panda | panda | Full compilation, runs on PandaBoard("panda") |
BUILDTYPE is divided into three types
BUILDTYPE | Features |
---|---|
user | Version released to the market, defaults without root access, adb disabled |
userdebug | Open root, adb access, generally used for real device debugging |
eng | Has maximum permissions (root), and has additional debugging tools, generally used for emulator |
make compile: can compile according to the number of CPU cores on your computer
# make -j$(nproc)
make -j10
Android Source Single Compile - Module#
In addition to full compilation, we can use single compile for a specific application module (e.g., Settings application module)
In the root directory of Android Source, execute the following command
source ./build/envsetup.sh
lunch xxx
Enter the Settings directory and use mm to compile
mmm packages/apps/Settings
In addition to the mm command, other commands can also be used for single compilation
Command | Function |
---|---|
mm | Compile the Module in the current directory (must enter the specified project directory to compile) |
mmm | Compile the Module in the specified directory, but do not compile its dependent Modules (can compile any specified project in any level of the Android source code directory structure) |
mma | Compile the Module in the current directory, including its dependent Modules |
mmma | Compile all Modules in the specified path, including their dependencies |
Run Emulator#
source ./build/envsetup.sh
lunch xxx
emulator