1. Virtual machine installation
1.1 Enter https://cn.ubuntu.com/download the official Chinese website to download the iso image
1.2 Here we download Ubuntu 18.04 LTS
1.3 Install the ubuntu system on the virtual VM machine. Note that compiling the source code requires at least 16G running memory and 400G disk space. Try to set it as large as possible.
2. Configure the compilation environment
2.1 Download android source code and install python
apt-get install python (Repo is built on specific features in Python 2.x and is not compatible with Python 3. To use Repo, install Python 2.x:)
If it is Ubuntu 18.04, you can only use python2.x
If it is Ubuntu 20.04, use python3.x
Since the environment variable defaults to python, you can use python3 -v to obtain the instructions.
But we can merge it using the following command
sudo ln -s /usr/bin/python3 /usr/bin/python
This way python -v can get the instructions
Encountered an error, no root permissions
apt-get install python
E: Unable to open lock file /var/lib/dpkg/lock-frontend - open (13: Insufficient permissions)
E: Unable to obtain dpkg frontend lock (/var/lib/dpkg/lock-frontend), please check whether you are running as root user?Solution:
Enter su root to gain permissions
If it prompts that authentication failed, change the password
dong@dong:~/桌面$ su root
密码:
su: 认证证败Solution:
Change root user password
sudo passwd root
Enter the command apt-get install python again. If an error occurs and resources are occupied, enter the command apt-get install python again. At this time, the installation can be successful
E: Unable to acquire lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire dpkg frontend lock (/var/ lib/dpkg/lock-frontend), is it occupied by other processes?Solution:
Perform uninstallation first: sudo rm /var/lib/dpkg/lock
Then execute the command to reconfigure: sudo dpkg --configure -a
Run the installation command again: sudo apt-get install python
If the following error occurs, it will be locked
dong@dong:~$ sudo dpkg --configure -a
dpkg: Error: Another process has locked dpkg frontendSolution: Execute the following commands in sequence
sudo rm /var/lib/dpkg/updates/*
sudo apt-get update
sudo apt-get upgrade
Uninstall update python version
Check version
python --version
Uninstall version
sudo apt-get purge python<version number>
Delete the Python installation directory
sudo rm -rf /usr/lib/python<version number>
Clean up residual files
sudo apt-get autoremove
sudo apt-get autoclean
Verify the uninstallation results. If the output shows "command not found" or a similar message, Python has been successfully uninstalled.
python --version
If you need to specify python, follow the steps below
sudo apt install python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 (python2 installation address) 2 (weight number)
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 (python3 installation address) 3 (weight number)sudo update-alternatives --config python
2.2 Install Git & Configure Git information
sudo apt-get install git
git config --global user.name dong
git config --global user.email [email protected]
2.3 Install curl
sudo apt-get install curl
If you download the source code directly, an error will be reported, prompting that curl is required.
dong@dong:~/Desktop$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
Command 'curl' not found, but can be installed with:
sudo snap install curl # version 8.1.2, or
sudo apt install curl # version 7.68.0-1ubuntu2.20See 'snap info curl' for additional versions.
We enter according to the prompts
sudo snap install curl # version 8.1.2
2.4 Download repo
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
//Open environment variable file
sudo vim /etc/profile
Add the following two lines
export PATH=~/.bin:$PATH
export REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo///Refresh cache
source /etc/profile
Download error
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to storage.googleapis.com:443Solution: If fanqiang is needed, we switch to Tsinghua mirror:
curl https://mirrors.tuna.english.edu.cn/git/git-repo > ~/bin/repo
The repo file may report an error and the following error occurs:
We have detected that the subnet you are in and/or the client you are using is downloading a large number of certain large binary files. To ensure the normal use of users, we have blocked such requests.
We have detected enormous traffic from your network or client and have blocked your requests to ensure the quality of service for normal users.
We have detected a large number of downloads of certain large binary files from your subnet and/or the client you are using and have blocked these requests to ensure normal user access.
We have detected a large number of downloads of certain large binaries on your subnet and/or clients. We will block these requests for your normal use.
You can try to change the network environment or change the client; you can also contact[email protected] and attach the following Party identifier.
solve:
This may be connected to a public and unsafe network. Downloading large binary files is prohibited. Change the host to another wifi and execute the repo again. It should be fine.
Executing sudo vim /etc/profile, an error message cannot be found for the vim command.
dong@dong:~/Desktop$ sudo vim /etc/profile
sudo: vim: command not foundSolution: vim needs to be installed
sudo apt-get install vim
2.5 Create source code storage directory
mkdir aosp (Create a new directory according to the actual situation)
cd aosp
An error is reported, indicating that the directory cannot be created.
mkdir: cannot create directory '/home/ubuntu/aosp': No such file or directory
solve:
First enter root mode:
sudo -s
Then enter the home directory
cd /home
Create the ubuntu directory again
mkdir /home/free/
Create aosp directory again
mkdir /home/ubuntu/aosp
2.6 View the branch to download
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest
cd manifest/
git branch -aUse q to exit preview
Or check the version code mark on Google’s official website
https://source.android.com/docs/setup/about/build-numbers?hl=zh-cn#source-code-tags-and-builds
For example, the corresponding mark of Android7.1.0
NDE63X | android-7.1.0_r7 | Nougat | Pixel XL、Pixel | 2016-11-05 |
NDE63V | android-7.1.0_r6 | Nougat | Pixel XL、Pixel | 2016-11-05 |
NDE63U | android-7.1.0_r5 | Nougat | Pixel XL、Pixel | 2016-11-05 |
NDE63P | android-7.1.0_r4 | Nougat | Pixel XL、Pixel | 2016-10-05 |
NDE63L | android-7.1.0_r2 | Nougat | Pixel XL、Pixel | 2016-10-05 |
NDE63H | android-7.1.0_r1 | Nougat | Pixel XL、Pixel | 2016-10-05 |
2.7 Initialize the warehouse
repo init - at https://aosp.tuna.tsinghua.edu.cn/platform/manifest
2.8 repo specifies Android version
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.0_r1
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r46
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r35
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-7.1.0_r1
Error: No python folder
dong@dong:~/Desktop/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r35
/usr/bin/env: "python": No such file or directorysolve:
View python installation location
whereis python3
Displayed as follows:
python3: /usr/bin/python3.8 /usr/bin/python3 /usr/lib/python3.8 /usr/lib/python3.9 /usr/lib/python3 /etc/python3.8 /etc/python3 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz
sudo ln -s /usr/bin/python3 /usr/bin/python
An error is reported. Google's warehouse cannot be downloaded. Tsinghua mirror needs to be switched.
root@dong:/home/dong/桌面/aosp# repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.0_r1
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 111] Connection refused
fatal: double check your --repo-rev setting.
fatal: cloning the git-repo repository failed, will remove '.repo/repo'solve:
Open the global variable configuration file
sudo gedit ~/.bashrc
Add global variables, add these two lines at the end and save:
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/ git/git-repo/'Make the configuration file effective
source ~/.bashrc
Error, repo command not found
root@dong:/home/dong/Desktop/aosp# repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.0_r1
Command "repo" not found, did you mean:
command 'reno' from deb python3-reno (2.11.2-2build1)
command 'repl' from deb mailutils-mh (1:3.7-2.1)
command 'repl' from deb mmh (0.4-2)
command 'repl' from deb nmh (1.7.1-6)
command 'rep' from deb rep (0.92.5-3build5)
command 'repc' from deb qtchooser (66-2build1)Try apt install <deb name>
solve:
Uninstall and reinstall repo
sudo apt-get remove repo
If it prompts that the version is wrong, follow the command to install the repo
root@dong:/home/dong/aosp# repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.0_r1
Command 'repo' not found, but can be installed with:
snap install git-repo # version 1.12.37-3, or
apt install repoSee 'snap info git-repo' for additional versions.
solve:
apt install repo
Error reported, repo setup failed
dong@dong:~/桌面/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r35
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 111] Connection refused
fatal: double check your --repo-rev setting.
fatal: cloning the git-repo repository failed, will remove '.repo/repo'solve:
Reinitialize the repo and set the repo environment variables
export PATH=~/.bin:$PATH
export REPO_URL=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
Successful examples:
dong@dong:~/桌面/aosp$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r35
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
remote: Enumerating objects: 4882, done.
remote: Counting objects: 100% (4882/4882), done.
remote: Compressing objects: 100% (2422/2422), done.
remote: Total 8618 (delta 4305), reused 2460 (delta 2460), pack-reused 3736
接收对象中: 100% (8618/8618), 4.18 MiB | 3.54 MiB/s, 完成.
处理 delta 中: 100% (5569/5569), 完成.
2.9 Synchronize source code
repo sync j8 (j8 is the number of threads opened, wait for the source code download to complete, wait for a long time, if it fails, please check the network, etc.)
Start downloading the source code, which takes about 5 to 6 hours and takes up more than 100 G of disk space.
Start syncing
dong@dong:~/桌面/aosp$ repo sync
remote: Enumerating objects: 5288, done.
remote: Counting objects: 0% (1/5288)
remote: Counting objects: 1% (53/5288)
remote: Counting objects: 2% (106/5288)
remote: Counting objects: 3% (159/5288)
remote: Counting objects: 4% (212/5288)
remote: Counting objects: 5% (265/5288)
remote: Counting objects: 6% (318/5288)
remote: Counting objects: 7% (371/5288)Download successful, 4 to 5 hours
In processing delta: 95% (32415/34113)
In processing delta: 96% (32750/34113)
In processing delta: 97 % (33208/34113)
Processing delta: 98% (33455/34113)
Processing delta: 99% (34110/34113)
Processing delta: 100% (34113/34113)
Processing delta: 100% (34113/34113), 413 local objects completed.
Fetching: 22% (252/1135) 1:10:04 | 4 jobs | 5:19 platform/external/icu @ exter..
Fetching: 100% (1135/1135) , done in 4h53m27.407sUpdate, it will take another hour
Checking out: 95% (1083/1135) platform/prebuilts/vndk/v29 Updating files: 73% (531Checking out: 97% (1103/1135) platform/system/keymaster Updating files: 73% (533/7 Updating files: 100% (724/724), completed.
Updating files: 100% (119/119), completed.
Updating files: 100% (111/111), completed.
Checking out: 97% (1108/1135) platform/prebuilts/gcc/linux-x86/host/x86_64-linuxChecking out: 97% (1109/1135) platform/prebuilts/gcc/linux-x86/host/x86_64-w64-mChecking out: 99% (1129/1135) platform/prebuilts/module_sdk/OnDevicePersonalizatChecking out: 100% (1135/1135), done in 1h23m34.934s
repo sync has finished successfully.
2.10 If failure occurs, you can replace the REPO_URL mirror source in the repo script.
REPO_URL = "https://gerrit.googlesource.com/git-repo"
Replace with
REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
Three linux vim edit save exit
vim /etc/profile
3.2 Edit files
Press i to edit
3.3 Save and exit
First pressesc to return to the command editing mode, and the Insert just now will disappear
In English :
:q! Do not save the file and force exit
:w Save the file without exiting the vi command
:wq Save the file and exit the vi command
Four driver downloads
4.1 Download the corresponding version of the driver from the official website
https://developers.google.cn/android/drivers#redfintp1a.221105.002
4.2 Find the driver file corresponding to piexl 5
4.3 Unzip to the aosp root directory
tar -xvzf qcom-redfin-tp1a.221005.002-e7e20f49.tgz -C ~/GitProjects/aosp/
tar -xvzf google_devices-redfin-tp1a.221005.002-3daf7ea0.tgz -C ~/GitProjects/aosp/
4.4 Run the decompressed script
./extract-qcom-redfin.sh
./extract-google_devices-redfin.sh
5 AOSP project source code structure
- abi Application Binary Interface Application binary interface, abi believes that students have encountered it when calling SO libraries. If the platform is not supported, then ABI does not support it.
- art Android Runtime Android runtime. This will compile the bytecode into binary machine code in advance and save it, which will load faster during execution. The Dalvik virtual machine is compiled after loading, so ART will be faster than Dalvik. Sacrifice space to gain time.
- bionic basic library, a bridge between the Android system and the Linux kernel. The phonetic symbol of Bionic is bīˈänik, which is translated as "bionic".
- bootable system startup and boot related programs
- build tool used to build the Android system, that is, used to compile the Android system
- cts Compatibility Test Suite compatibility test
- dalvik dalvik virtual machine, a virtual machine used to parse and execute dex files
- developers developer directory
- development directory, such as application, application is in it, apps
- Devices device-related configuration information, such as Sony, HTC, and their own products, can be defined in this directory.
- docs documentation
- external open source module related files
- frameworks system architecture, the core of Android
- hardware hal layer code, hardware abstraction layer
- libcore core library
- libnativehelper native help library, implementing JNI related files
- ndk native development kit
- out output directory, the directory generated after compilation, the relevant output is here
- packages application packages. Some system applications are here, such as Bluetooth, Launcher, camera, dialing, etc.
- pdk Plug-in Development Kit (PDK) is designed to help you build your own pattern projects
- platform_testing platform testing
- prebuilts precompiled files under x86/arm architecture
- sdk software development kit
- system underlying system files
- toolchain toolchain
- tools tool file
- Makefile mk file, used to control compilation
Six system compilation
6.1 Android10 or above needs to install the following toolkits
sudo apt install unzip zip libssl-dev libffi-dev gnupg flex bison gperf build-essential curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libz-dev ccache libgl1-mesa-dev libxml2-utils xsltproc
6.2 Install openjdk8
sudo apt-get install openjdk-8-jdk
(If the installation is unsuccessful, check whether ubuntu has changed sources and whether there is an updated software package list)
sudo apt-get update
6.3 Install dependencies
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache
sudo apt-get install libssl-dev
If you install sudo apt-get install libesd0-dev and the error Unable to locate package libesd0-dev is reported, what is the solution?
sudo gedit /etc/apt/sources.list //Add the following two lines at the end of the line
deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main universe
6.4 Set and enable ccache (to speed up recompiling source code. Optional)
export USE_CCACHE=1 (Add it to .bashrc in your home directory)
export CCACHE_DIR=/home/ubuntu/.ccache (specify a cache directory, or not specify it) , the default directory is .ccache in your current user directory)
aosp/prebuilts/misc/linux-x86/ccache/ccache -M 50G (This command is in the Android source code, the cache size is according to your own the hard disk to adjust appropriately)
source ~/.bashrc (the source command makes the modification take effect immediately)
6.5 Compilation
cd aosp
source build/envsetup.sh
lunch 47 (The version selected for lunch is based on the actual situation)
make -j16 (related to CPU, Adjust numbers appropriately)
6.6 If the following error is reported during compilation, it indicates that there is insufficient memory. Ensure that there is more than 16GB of memory.
98% 392/397] analyzing Android.bp files and generating ninja file at out/soong
FAILED: out/soong/build.ninja
cd “KaTeX parse error: Expected 'EOF', got '&' at position 49: …soong_build")" &̲& BUILDER="PWD/KaTeX parse error: Expected 'EOF', got '&' at position 50: …soong_build")" &̲& cd / && env -…BUILDER” --top “$TOP” --soong_out “out/soong” --out “out” -o out/soong/build.ninja --globListDir build --globFile out/soong/globs-build.ninja -t -l out/.module_paths/Android.bp.list --available_env out/soong/soong.environment.available --used_env out/soong/soong.environment.used.build Android.bp
Killed
00:31:16 soong bootstrap failed with: exit status 1solve:
1. Return to the root directory
cd
2. Check the size of the swap area
free -m sudo dd if=/dev/zero of=/swapfile bs=1G count=16 sudo swapon /swapfile 8. Open swapfile sudo mkswap -f /swapfile 7. Create file system sudo chmod 0600 /swapfile 6. Grant permissions 5. Re-create the spap file sudo rm /swapfile 4. Delete the original swap file sudo swapoff /swapfile
3. Close the original swap file
6.7 Delete the results of the last compilation. This step is not required for the first compilation.
make clobbe
If it prompts that make cannot be found, you need to install the make tool
oot@dong:/home/dong/Desktop# make clean
Command 'make' not found, but can be installed with:
apt install make # version 4.2.1-1.2, or
apt install make-guile # version 4.2.1-1.2Solution: Enter the following command as prompted
apt install make # version 4.2.1-1.2
6.8 If the compilation is successful, the following content will be displayed:
Creating filesystem with parameters:
Size: 2147483648
Block size: 4096
Blocks per group: 32768
Inodes per group: 8192
Inode size: 256
Journal blocks: 8192
Label: system
Blocks: 524288
Block groups: 16
Reserved block group size: 127
Created filesystem with 2216/131072 inodes and 199826/524288 blocks
[100% 7669/7669] Install system fs ima.../target/product/generic_x86/system.img
out/target/product/generic_x86/system.img+ maxsize=2192446080 blocksize=2112 total=2147483648 reserve=22146432#### make completed successfully (01:24:41 (hh:mm:ss)) ####
The image file will be generated in the source code and directory out/target/product/angler directory:
- system.img: system image
- ramdisk.img: root file system image
- userdata.img: User data image
- recovery.img:recovery image
- boot.img: boot image
- vendor.img: driver image
Finally, three important image files will be generated in the out/target/product/generic_x86/ directory: system.img, userdata.img, and ramdisk.img. There are roughly three image files introduced:
- system.img: System image, which contains the main directories and files of the Android system. It is parsed through init.c and mounted to the /system directory.
- userdata.img: User image, which stores user data in the Android system. It is parsed through init.c and mounted to the /data directory.
- ramdisk.img: Root file system image, including some important files for starting the Android system, such as init.rc.
6.9 Other command descriptions
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
- clean - m clean will delete all output and intermediate files for this configuration document. This content is the same as rm -rf out/
The mmm instruction is used to compile the specified directory. Generally speaking, each directory only contains one module. For example, here we want to compile the Setting module and execute the instruction :
mmm packages/apps/Settings/
6.8 Reference
https://www.cnblogs.com/stlong/p/17654389.html
https://blog.csdn.net/lucky_tom/article/details/127825300
https://blog.csdn.net/m0_37099118/article/details/123767615
https://www.cnblogs.com/stlong/p/17645300.html
https://www.jianshu.com/p/5eaec7be3da7
https://www.jianshu.com/p/197096d3206d
7. Delete AOSP source code on Ubuntu
7.1 Open the terminal and enter the directory of the AOSP source code. If you don't know the specific location of the source code, you can use the following command to find it: This will search the entire system for the build/envsetup.sh
file, which exists in the AOSP source code directory.
find / -name "build/envsetup.sh"
7.2 Execute the following command to enter the AOSP source code environment:
source build/envsetup.sh
7.3 Enter the AOSP source code directory:
cd <AOSP source code directory>
7.4 Execute the following command to clear the source code: all generated files and directories will be cleared.
make clean
7..5 Delete the AOSP source code directory: The source code will be permanently deleted
rm -rf <AOSP source code directory>
8. Collection of tools that need to be installed
sudo apt-get install openjdk-8-jdk //It goes without saying about jdk
sudo apt-get install python //Repo is based on a specific feature in Python 2.x Functionally built, not compatible with Python 3
sudo apt-get install phablet-tools //git toolkit
sudo apt-get install curl //Upload and Tool for downloading data
sudo apt-get install build-essential //Provide list information of software packages required for compilation program
sudo apt-get install make //Source code Compilation tools
sudo apt-get install gcc //GNU compiler suite
sudo apt-get install g++
sudo apt- get install libc6-dev //Shared library
sudo apt-get install patch //Patch tool
sudo apt-get install texinfo //Document system sudo apt-get install valgrind //Memory checker sudo apt-get install ncurses-dev //Needed when compiling the kernel sudo apt-get install git-core gnupg //Git toolkit, although git is available , but be prepared
sudo apt-get install libncurses-dev //Essential libraries for the system
9. Simulator installation
9.1 When flashing a Google phone, you need to download the Google hardware driver. Find the corresponding model and click the link to download
Download URL: https://developers.google.cn/android/blobs-preview
9.2 Extract the driver, copy the downloaded driver compressed package to the Android source code root directory, and decompress it. After decompression, you will get a .sh script.
9.3 Decompression driver
tar -zxvf google_devices-oriole-sp2a.220305.013.a3-04c512f4.tgz
9.4 Execute the extract-google_devices-oriole.sh script to extract the driver. When running the prompt "Press Enter to view the license", enter Enter and then enter d to turn the page.
./extract-google_devices-oriole.sh
9.5 When prompted to enter "I ACCEPT", press Enter and press Enter to complete the driver extraction. After completion, the source code root directory will have a vendor directory.
9.6 Set up the code compilation environment. You need to configure the compilation environment every time you restart the shell. Execute the following command in the root directory:
source build/envsetup.sh
or
. build/envsetup.sh
9.7 After executing the build/envsetup.sh script, configure several shell commands in the environment. You can then use these commands to select device targets and compile, enterhmm command to view the complete command list:
- lunch: lunch <product_name>-<build_variant>
Selects <product_name> as the product to build, and <build_variant> as the variant to
build, and stores those selections in the environment to be read by subsequent
invocations of 'm' etc.
- tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
Sets up the build environment for building unbundled apps (APKs).
- banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user]
Sets up the build environment for building unbundled modules (APEXes).
- croot: Changes directory to the top of the tree, or a subdirectory thereof.
- m: Makes from the top of the tree.
- mm: Builds and installs all of the modules in the current directory, and their
dependencies.
- mmm: Builds and installs all of the modules in the supplied directories, and their
dependencies.
To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Same as 'mm'
- mmma: Same as 'mmm'
- provision: Flash device with all required partitions. Options will be passed on to fastboot.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- gogrep: Greps on all local Go files.
- jgrep: Greps on all local Java files.
- ktgrep: Greps on all local Kotlin files.
- resgrep: Greps on all local res/*.xml files.
- mangrep: Greps on all local AndroidManifest.xml files.
- mgrep: Greps on all local Makefiles and *.bp files.
- owngrep: Greps on all local OWNERS files.
- rsgrep: Greps on all local Rust files.
- sepgrep: Greps on all local sepolicy files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
- allmod: List all modules.
- gomod: Go to the directory containing a module.
- pathmod: Get the directory containing a module.
- outmod: Gets the location of a module's installed outputs with a certain extension.
- dirmods: Gets the modules defined in a given directory.
- installmod: Adb installs a module's built APK.
- refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod.
- syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary.
9.8 Use lunch to start the emulator
lunch sdk_phone_x86_64
9.8 Use lunch to start Car
lunch aosp_oriole-userdebug
Different devices have different selection goals. Choose according to the device directory options given on the Android official website
Website: https://source.android.google.cn/setup/build /running#selecting-device-build
Start compiling in 9.9. Enter m or make to compile the entire Android source code. You can also use the parameter -j to specify the number of threads.
m
or
make -j8
If you only compile a certain part, first switch to the corresponding directory and use the mm command to compile.
mm
Ten flash machine
10.1 Flashing method
Android simulation device, enter the emulator command to start the Android emulator
emulator -verbose -show-kernel -cores 4
10.2 Download adb and fastboot tools for window system, unzip and add the directory to the environment variable
Download link: https://developer.android.google.cn/studio/releases/platform-tools#downloads
10.3 Start USB debugging on the mobile phone
To use adb on a device connected via USB, USB debugging must be enabled in the device's system settings
10.4 To install the driver, find the corresponding device in the device manager to install the driver. After installation, there will be an additional "Android Device" device.
Download link:https://developer.android.google.cn/studio/run/win-usb
10.5 Unlock and load the bootloader
- Enter "adb reboot bootloader" in cmd to enter fastboot mode and check whether it is in lock mode
- If you are in locked mode, enter "fastboot flashing unlock" to unlock, and you need to confirm on your phone.
- After being in unlocked mode, the device will first enter fastboot mode every time it is started. If it needs to be in locked mode, enter the "fastboot flashing lock" command
10.6 Flash device
- Enter "adb reboot bootloader" in cmd to enter fastboot mode
- Switch to the Android image directory and enter the "fastboot flashall -w" command to flash the image to the device. After the flashing is completed, wait for the device to restart and the native Android system will be running.