1. Preparation Android officially announced that AOSP has always been developed and tested in Ubuntu LTS versions. So to avoid any other unnecessary troubles, please use Ubuntu and other Ubuntu-based distributions. Minimum environmental requirements:
2. Download Aosp source code 1. Install GIT First you need to install Git, because the source code is managed with Git. sudo apt - get install git Next, create a bin folder and add it to the PATH, a bit like the Windows environment variables. mkdir ~/ bin 2. Install Python environment sudo apt - get install python 3. Install repo and configure repo is a python script (so we need to configure the Python environment above), because the Android source code contains hundreds of git libraries, simplifying the tools to help manage the git Android version library. (1) Install the library downloaded by curl: sudo apt - get install curl (2) Download the repo and set the executable permissions. curl https : // mirrors .tuna .tsinghua .edu .cn / git / git - repo > ~/ bin / repo (3) Add download source As for Google's AOSP, because the FQ and data volume are too large, and it requires a VPN to affect the speed, domestic mirrors are given priority (this article uses the Tsinghua source). export REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/' 4. Initialize and synchronize source code (1) Create a folder Create an AOSP folder and cdd into it. You will need to download the source code here later: mkdir aosp (2) Initialize the Aosp warehouse repo init - u https : // aosp .tuna .tsinghua .edu .cn / platform / manifest (3) Initialize and specify the version repo init - u https : // aosp .tuna .tsinghua .edu .cn / platform / manifest - b android - 8.0 .0_r36 AOSP corresponding relationship view address: Correspondence (4) Start synchronizing source code repo sync - j4 As Android source code becomes larger and larger, the probability of repo sync failure is also increasing. Therefore, we can avoid using repo sync and use the method of downloading pre-downloaded packages to download source code. 5. Pre-download package method 1. Download the pre-download package Download via Thunder on Windows or Linux : https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar 2. Unzip the pre-downloaded package tar xf aosp - latest .tar 3. View branches cd .repo / manifests 4. Select the version you want to synchronize in the aosp directory repo init - b android - 9.0 .0_r55 5. Prevent the script from getting stuck when downloading source code Starting source code downloads through custom Shell scripts can effectively prevent the script from getting stuck when synchronizing source code. (1) Create a new down.sh file in the AOSP folder # !/ bin / bash (2) Execute the down.sh file sh down.sh 3. AOSP source code directory structure
4. AOSP source code compilation Compiling AOSP source code requires configuring the JAVA environment. 1. Install the Java compilation environment sudo apt - get update 2. Enter the AOSP folder and compile (1) Initialize the compilation environment source build / envsetup.sh (2) Delete the results of the previous compilation. This step is not required for the first compilation. make clobber (3) Select the compiled version corresponding to the device lunch XX Select the compilation version corresponding to the device. For example, compile the development engineer version lunch aosp_x86-eng, which is convenient for debugging Compilation version selection If the lunch command does not have a corresponding compiled version, the following information will be output: You 're building on Linux Here you need to select the format of the compilation target (select the previous number and press Enter). The format of the compilation target is composed of BUILD-BUILDTYPE. For example, the BUILD of aosp_arm-eng is aosp_arm and the BUILDTYPE is eng. BUILD indicates the environment in which the compiled image can run, aosp stands for the Android open source project, and arm means that the system runs on an arm architecture processor; BUILDTYPE refers to the compilation type, which has the following three types:
(4) Start compiling make - j8 The number after j is the number of threads, which shall not exceed the total number of threads on your CPU. A successful compilation will display as follows: Creating filesystem with parameters : The image file will be generated in the source code directory out/target/product/angler:
Finally, three important image files will be generated in the out/target/product/generic_x86/ directory: system.img, userdata.img, and ramdisk.img. Here is a brief introduction to the three image files:
3. Compilation error resolution (1) libncurses.so.5 is missing Error message: error while loading shared libraries : libncurses .so .5 : cannot open shared object file : No such file or directory Solution: sudo apt - get update (2) Lack of M4 Error message: / bin / bash : m4 : command not found Solution: sudo apt - get install m4 (3) Remove all localization settings Error message: FAILED : out / host / linux - x86 / obj / EXECUTABLES / checkpolicy_intermediates / policy_scan.c Solution: export LC_ALL = C (4) Problems with xmllint Error message: / bin / bash : xmllint : command not found Solution: sudo apt - get install libxml2 - utils (5) Insufficient compilation memory Error message Try increasing heap size with java option '-Xmx<size>' error Solution: export JACK_SERVER_VM_ARGUMENTS = "-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g" 5. Run the simulator Start the simulator After the compilation is complete, you can run the Android virtual machine with the following command. Since the source and lunch commands have been executed before, you can run them directly: source build / envsetup.sh The simulator will start 6. Compile a single module from AOSP source code The above compilations are all for the entire Android system. If we want to compile the system's Settings application module, this belongs to the source code single compilation of a module. Execute in the AOSP root directory: source build / envsetup.sh Enter the Settings directory: cd packages / apps / Settings Compile the modules in the current directory through mm, and do not compile dependent modules. mm After the compilation is successful, there will be a prompt to generate the file storage path. In addition to the Settings.odex file, Settings.apk will also be generated in the out/target/product/generic_x86/system/priv-app/Settings directory. In addition, there are the following commands for single editing:
If you modify the source code of the system module, there are two ways to view the generated APK file:
|
<<: Detailed explanation of R8 in Android
>>: iOS 16.4 Quick Security Response Update
In the hot summer, people still want to eat somet...
Previously, the State Administration of Radio, Fi...
Based on the research and analysis answers given ...
The poor reading and writing experience tells us ...
【51CTO.com original article】 Activity description...
Introduction The apps that were rejected this tim...
To understand the issue of note collection, just ...
What events are included in the Beijing Winter Ol...
In the eyes of Chinese users, the product quality...
On August 8, the first JD Technology Salon was he...
Is the Arctic on fire? Author: Fan Gang You may f...
I believe everyone is familiar with information f...
However, with the rapid expansion of product scal...
There is a physical indicator whose name is diffi...
Nintendo Switch has been on the market for more t...