pixel 3a compile and install android12

The last update time of the article is: November 21, 2022 00:59:51

0. Equipment preparation

  • pixel 3a
  • ubuntu20 virtual machine 16g memory 300G storage 6-core cpu

Suggestions for ubuntu20: start with 16G of memory, no less than 250G of storage, no less than 4 cores of cpu, otherwise the speed will be extremely slow, and there will be unexpected errors, such as insufficient memory during compilation

1. Configure the environment

refer to https://source.android.google.cn/docs/setup/build/initializing

sudo apt-get install -y git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig git curl vim

# Create a soft connection, ubuntu20 does not have python environment variables by default
sudo ln -s /usr/bin/python3 /usr/bin/python

# Fill in your Name and Email
git config --global user.name Your Name
git config --global user.email you@example.com
copy

2. Determine the source code version

Open https://developers.google.com/android/images , find "sargo" for Pixel 3a, sargo is the code name of pixel 3a.

What I want to compile here is the latest version of android12: 12.1.0 (SP2A.220505.008, Sep 2022). (The following Link is the official original ROM, which can be directly downloaded and flashed into the phone)

Next, determine the branch corresponding to the android source code version ROM and the android source code version, open https://source.android.google.cn/docs/setup/about/build-numbers , you can see that the version corresponding to SP2A.220505.008 is android-12.1.0_r27

Make sure the version you need to download is android-12.1.0_r27, so you won’t download the wrong source code version

3. Download the source code

# Download the repo tool. Repo is a code version management tool. It is composed of a series of Python scripts and encapsulates a series of Git commands to manage multiple Git repositories in a unified manner.
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /usr/local/bin/repo
chmod a+x /usr/local/bin/repo

# Modify the code source
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
mkdir android12
cd android12

# download code
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-12.1.0_r27
repo sync -j4
copy

The -j parameter when downloading the code is the number of threads, and setting it to 4 here is generally enough. However, the download process is relatively long and there may be problems, so this step can be run in a script loop to prevent network interruption

#!/bin/bash
repo sync -j4
while [ $? -ne 0 ]
do
echo "======sync failed ,re-sync again======"
sleep 3
repo sync -j4
done
copy

I hung up for one night and finished downloading. In fact, the network speed is pretty fast, and it can run up to 6Mb/s, but the data volume is relatively large, roughly estimated to be about 80G.

4. Download the driver

Refer to the official documentation: https://source.android.google.cn/docs/setup/build/downloading#obtaining-proprietary-binaries

exist https://developers.google.cn/android/drivers Find the driver corresponding to SP2A.220505.008 on the page, and download both:

wget https://dl.google.com/dl/android/aosp/google_devices-sargo-sp2a.220505.008-772e1993.tgz
wget https://dl.google.com/dl/android/aosp/qcom-sargo-sp2a.220505.008-8c718226.tgz
tar -zxf qcom-sargo-sp2a.220505.008-8c718226.tgz
tar zxvf google_devices-sargo-sp2a.220505.008-772e1993.tgz
copy

Copy the two decompressed sh scripts to the android source code directory for execution. After successful execution, the source code directory will contain the following folders. When executing, you need to enter the keyboard ENTER and input I ACCEPT

cp extract-qcom-sargo.sh android12/
cp extract-google_devices-sargo.sh android12/
cd android12/
./extract-google_devices-sargo.sh 
./extract-qcom-sargo.sh 
copy

5. Code compilation

# The following steps need to be performed every time a new terminal is opened
source build/envsetup.sh
lunch
copy

Then select the device version, you can refer to https://source.android.com/docs/setup/build/running#selecting-device-build , here I chose aosp_sargo-userdebug, serial number 35

Which would you like? [aosp_arm-eng] 25

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=12
TARGET_PRODUCT=aosp_sargo
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.0-53-generic-x86_64-Ubuntu-20.04.5-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=SP2A.220505.008
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/google/bonito hardware/google/av hardware/google/camera hardware/google/interfaces hardware/google/pixel hardware/qcom/sdm845 vendor/google/camera vendor/qcom/sdm845 vendor/google/interfaces vendor/google_devices/common/proprietary/confirmatioui_hal vendor/google_nos/host/android vendor/google_nos/test/system-test-harness vendor/qcom/sargo/proprietary
============================================
copy

Then compile, refer to https://source.android.com/docs/setup/build/building

m
 use m Build everything. m can use-jN Parameters to handle parallel tasks. If you do not provide-j parameter, the build system automatically chooses the parallel task count it thinks is best for your system.
As mentioned above, you can do this via the m List their names on the command line to build specific modules rather than full device images. also, m Some fake targets for special purposes are also provided. Some examples are:

droid - m droid is a normal build. This target is here because the default target requires a name.
all - m all Construct m droid everything that does, plus no droid Label everything. The build server runs this to make sure everything in the build tree has Android.mk document.
m - Run the build from the top of the tree. This is useful because from a subdirectory you can run make . If you set TOP environment variable and it will use it. If you don't, it looks up the tree from the current directory, trying to find the top of the tree. You can do this by running without arguments m to build the entire source tree, or specific targets by specifying their names.
mma - Build all modules and their dependencies in the current directory.
mmma - Build all modules and their dependencies in the provided directory.
croot - cd to the top of the tree.
clean - m clean Delete all output and intermediate files for this configuration. This is the same as rm -rf out/same.
run m help Check m Additional pseudo-targets provided.
copy

I have problems compiling

[ 96% 124885/129423] soong_build docs out/soong/docs/soong_build.html
FAILED: out/soong/docs/soong_build.html
rm -f out/soong/docs/* && out/soong/.bootstrap/bin/soong_build --soong_docs out/soong/docs/soong_build.html "--top" "/home/yanq/Desktop/android12" "--out" "out/soong" "-n" "out" "-d" "out/soong/build.ninja.d" "-t" "-l" "out/.modu
le_paths/Android.bp.list" "-globFile" "out/soong/.bootstrap/build-globs.ninja" "-o" "out/soong/build.ninja" "--available_env" "out/soong/soong.environment.available" "--used_env" "out/soong/soong.environment.used" "Android.bp"
Killed
09:22:38 ninja failed with: exit status 1
copy

This is because the memory is not enough, so reduce the number of compilation threads and continue compiling:

m -j4
copy

It took more than four hours to compile.

[100% 4454/4454] Target vbmeta image: out/target/product/sargo/vbmeta.img
#### build completed successfully (40:49 (mm:ss)) ####
copy

6. Flash

Next, flash the compiled system into the phone

# Reboot to fastboot mode
adb reboot bootloader
# The following step can not be executed, because it has been unlocked by default
fastboot flashing unlock

# set system location
export ANDROID_PRODUCT_OUT=/home/yanq/Desktop/android12/out/target/product/sargo/

# brush in
fastboot flashall -w
copy

The system interface is relatively simple, and root privileges are automatically unlocked.

7. Reference

Tags: Android Cyber Security https

Posted by nowaydown1 on Mon, 21 Nov 2022 08:38:38 +0530