Ubuntu20.04 Compile Android 10 source code and burn the source code to pixel3's guide to avoiding pits

lab environment

  1. Ubuntu20.04
  2. pixel3

Download the Android source tree

To download the android source code, you can choose to download the latest version, or you can download the specified branch . If you can use the scientific Internet, it is recommended to download from the source tree of google. If not, it is recommended to use the Tsinghua mirror: https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/ , the link to the mirror tutorial has been given in detail, here I won't repeat them one by one

  1. Download the repo tool:
// 下载repo工具
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
  1. After installing Repo, set up your own client to access the code library: here you need to register a google account by yourself
(1)创建一个文件夹用来存放源码
mkdir Pixel3
cd Pixel3
(2)使用google帐号和真实姓名去配置Git
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
(3)运行repo init 获取最新版本代码或者指定分支
repo init -u https://android.googlesource.com/platform/manifest // 获取最新源码
repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r1// 指定分支
  1. Download the Android source tree
repo sync

Install the phone driver version on pixel3

  1. In the official website to find the phone model and the Android source code Build Number version of the driver that corresponds to
    where I downloaded the source code is android-10.0.0_r1, so it's Build Number QP1A.190711.019
    Insert picture description here
    then to drive the official website to find and download the corresponding driver information Come down
    Insert picture description here

  2. Unzip to the root directory of the source code just downloaded

  3. Enter the following code in the command line, and then press Enter to read the agreement, but because the agreement is too long, you can press ctrl+c to interrupt, here you will be prompted to enter I ACCEPT, after the input, you can extract the image

./extract-google_devices-blueline.sh
./extract-qcom-blueline.sh

Insert picture description here

  1. After the extraction is successful, a vendor directory will be generated in the root directory
    Insert picture description here

Compile Android source code

Note that compiling the source code requires at least 16GB of memory, so you need to increase the swap partition. For detailed steps, please refer to my first blog post

source build/envsetup.sh
lunch aosp_blueline-userdebug
make -j12

Android Studio import Android system source code

  1. After the compilation is successful, execute the following commands to compile the source code idegen module and generate the AS configuration build (*ipr):
mmm development/tools/idegen/
development/tools/idegen/idegen.sh

After completion, you will see three new files in the root directory:
android.iml (used to record the modules, dependencies, and sdk versions contained in the project)
android.ipr (specific configuration of the project, code and dependent lib information) android.iws (personal configuration information)

  1. Change the android.iml android.ipr permission to 777
sudo chmod 777 android.iml
sudo chmod 777 android.ipr
  1. Open Android studio, import the existing project, select the .ipr file in the root directory

Importing source code into Android Studio is too slow

sudo vim /etc/sysctl.conf

After entering the file, press i to enter the editing mode

Add at the end of the file

fs.inotify.max_user_watches = 524288

After inputting this passage, press Esc to enter normal mode, and then press: then input wq (means write and save)

Effective document

sudo sysctl -p –system // 生效文件

Brush in the image file just compiled on pixel3

  1. Connect pixel3 to the computer and enter bootloader mode
adb reboot bootloader
  1. Unlock phone
fastboot flashing unlock
  1. Enter fastbootd mode, the reference document is
    Insert picture description here
// (1) 方法一:在bootloader模式下输入
fastboot reboot fastboot
// (2)方法二:返回Android系统,输入以下命令
adb reboot fastboot
  1. Enter the following command in the command line
source ./build/envsetup.sh
  1. Enter the following command in the command line
lunch aosp_blueline-userdebug
  1. Enter the generated product path, enter the following command in the command line
cd  $ANDROID_PRODUCT_OUT
  1. Burn the compiled image file, enter the following command in the command line
fastboot flashall -w 

Insert picture description here

Avoid the pit

  1. When choosing a flashing phone, don’t buy the pixel2 US version, its bootloader cannot be unlocked. If you want to flash the pixel2 phone, you need to buy the European version.
  2. If you have to flash the newly compiled image file 3 or 4 on pixel3 before importing the image, otherwise you will encounter "Value too large for defined data type" when flashing the image file
  3. Be sure to flash the machine in fastbootd mode, otherwise you will encounter an error when flashing to the System:'Partition should be flashed in fastbootd'
  4. : If the original system of the phone is Android 11, if you burn the image file of Android 10.0 to the device, it will fail to burn. It is recommended to first go to the official website to burn the factory images of the compiled source branch, and then burn the image file of Android 10.0
  5. If "wait for any devices" appears after the input of fastboot flashall -w, then flash the newly compiled image file on pixel3. These steps need to be executed under root privileges.

Final rendering

Insert picture description here

Reference link
https://blog.csdn.net/weixin_45767368/article/details/105962606?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-6&spm=1001.2101.3001.4242
https://developers.google.com/android /drivers#bluelineqp1a.190711.019
https://source.android.google.cn/devices/bootloader/fastbootd?hl=zh-cn
https://www.jianshu.com/p/1f4a2b18246a

Guess you like

Origin blog.csdn.net/weixin_38355732/article/details/114044577