Compile and flash AOSP image - YangYiyu/JMTracker GitHub Wiki
1. Download AOSP source code
Sync the source code from repository (e.g., Tsinghua mirror).
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-11.0.0_r25 # The version name is after "-b"
repo sync # Or use "repo sync -j8" where j8 represents using 8 threads.
2. Download and install device drivers
- You can find drivers for Nexus and Pixel series on the website. It is important to note that each driver has a specific code that needs to correspond with the build number of the AOSP source code you have downloaded.
- After decompression, you will get two shell files. Copy them to the root directory of the downloaded AOSP source code.
- Execute the two extracted shell files. When prompted for a license, press enter to agree. Use the spacebar to scroll to the end and enter "I ACCEPT".
3. Prepare environment for compliling
- Execute
source build/envsetup.sh
to set up the necessary environment variables in the shell. - Execute
make clean
to clear previous compilation results. - To select a build target, use the
lunch
command. The syntax is as follows:
lunch product_name-build_variant
# the "product_name" part is the device alias, while "build_variant" part refers to the specific variant.
# For example: lunch aosp_coral-userdebug
You can find a list of product builds here, while the variants include: user, userdebug, and eng.
4. Compile source code
m -j32 # Enable 32-thread compilation
Compiling AOSP source code is a memory and time-intensive task. It is recommended to use a high-configured server and a separate thread window for the process.
5. Flash the image into a Android device
- Find an unused Android smartphone with an unlocked Bootloader (each model has its own method, tutorials can be found easily online).
- Configure the fastboot tool in the computer system, you can either compile it using the
make fastboot
command in the aosp directory or download it directly from the website. - Enter fastboot mode on your phone, you can either press the corresponding key combination during startup or use the following command:
adb reboot bootloader
- Make sure to install Android USB driver on your computer to avoid the situation where the device cannot be found after the phone restarts.
- Set the environment variable
ANDROID_PRODUCT_OUT
on your computer to the directory of the compiled image, such as "....../aosp/out/target/product/coral". - Navigate to the image directory on your computer and proceed with the flashing process:
cd ..../aosp/out/target/product/coral
fastboot flashall -w
- After the flashing process is complete, the phone will automatically power on and enter the new system.