Source code and compilation
Step 1 : Create an empty directory to store the source code:
mkdir aosp
cd aosp
Step 2 : Get the latest version of the repo and checkout the android-8.1.0_r1 branch:
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r1
Among them, android-8.1.0_r1
represents the source code mark, which means that we will obtain the source code of Android 8.1. If you want to view the source code mark of other versions, please refer to source code mark and build .
Step 3 : Download the Android source code from the repository specified in the default manifest to the local working directory:
repo sync
Step 4 : Create a local branch and associate all repositories on the repo:
repo start ycx-dev --all
Step 5 : Use envsetup.sh
the script to initialize the compilation environment:
source ./build/envsetup.sh
Step 6 : Select the compilation target:
lunch aosp_arm64-eng
The format description of the compilation target : the format of the compilation target is BUILD-BUILDTYPE, such as the target aosp_arm64-eng, its BUILD is aosp_arm64, and the BUILDTYPE is eng.
BUILD refers to the specific name of the combination of specific functions, which means the environment in which the compiled image can run. For example, aosp (Android Open Source Project) in aosp_arm64-eng represents the Android open source project, and arm means that the system is running on the arm architecture. On the processor, arm64 refers to the 64-bit arm architecture processor
To view the cpu architecture of an Android device, you can execute the command:adb shell getprop ro.product.cpu.abi
BUILDTYPE refers to the compilation type, usually there are three types:
- user: Indicates that the compiled system image version can be officially released to the market, and this version cannot be rooted
- userdebug: based on the user version, root authority and debug authority are opened
- eng: Indicates the development engineer version, with root authority, and also comes with many debug tools
If we enter the lunch command in the terminal, all compilation targets will be listed:
Step 7 : Start compiling (set 8 threads to compile at the same time):
m -j8
The more threads involved in compiling, the better. It is usually determined according to the core of your machine's cup. The formula is: core * 2, which is twice the core of the current CPU .
We can execute cat /proc/cpuinfo| grep "cpu cores"| uniq
the command to view the number of cores of the computer cpu.
If the compilation process goes well, we will see the following screen in the terminal, indicating that the compilation is successful!
Step 8 : If the compilation target selected by our lunch is 1-6, then we can directly execute the following command to run the virtual machine to see the effect:
emulator
After a while, we can operate the system firmware we just compiled successfully on the virtual machine.
If the compilation target selected by our lunch is not 1-6, then we can compile the firmware to run on the real device, the specific steps are as follows.
Step 9 : Enter fastboot mode
adb reboot bootloader
Step 10 : Unlock the bootloader
fastboot flashing unlock
Step 11 : Flash the device
fastboot flashall -w
-w
option will wipe /data
the partition ; this option can be added when flashing a specific device for the first time, and it can be left out in other cases.
If the flashing is successful, the terminal prints the following screen, which means that the flashing is successful, just wait for the machine to restart automatically.
compilation problem
Error 1 : flex-2.5.39: loadlocale.c:130:_nl_intern_locale_data
Solution : Enter the command in the terminal: export LC_ALL=C, and then recompile.
Error 2 : xmllint: command not found
Solution : Enter the command in the terminal: sudo apt-get install libxml2-utils, and then recompile.
Compile a single module and run
For example, if we modify the code of the SystemUI module, we need to compile it and run it on the machine to see the effect, then it can be like this,
Step 1 : Execute the compilation command in the current source code directory:
make SystemUI
After a while, you can see that the compilation is successful:
Step 2 : Get system write permission:
adb root && adb remount
Step 3 : Next, push the compiled product to the device:
adb push out/target/product/xxx/product/priv-app/SystemUI /system/product/priv-app/
Step 4 : Restart the upper layer of the device:
adb shell stop && adb shell start
After restarting, you can see the modified effect.