操作系统:ubuntu 18.04 LTS
手机:谷歌手机Pixel 3a
下载源码版本:android-12.0.0_r9
清华镜像源码下载教程
谷歌源码下载教程
虽然在ubuntu可以科学上网,但是个人认为下载源码还是在清华镜像站tuna进行源码下载比较好,至于它的优点啊,相对快,相对稳定吧。
在下载源码前,首先提一下。
谷歌说,首先要了解特定设备的出厂映像,而非先了解如何下载源代码,请参阅选择设备编译系统。
简单来说,就是你下载的这套源码,在进行编译配置与选择lunch设备时,能不能找到你谷歌手机的代号。
个人经验:先在Android 源码代号列表查看你下载的源码版本是否支持你的设备,我一开始就犯了这个错,我下载了标记android-12.0.0_r13版本,结果我在我编译时,没有找到选项"lunch aosp_sargo-userdebug(Pixel 3a的代号为sargo)",折腾一天最后才发现下错源码了
build ID | 标记 | 版本 | 支持的设备 | 安全补丁程序级别 |
---|---|---|---|---|
SD1A.210817.036.A8 | android-12.0.0_r13 | Android12 | Pixel 6、Pixel 6 Pro | 2021-11-05 |
… | … | … | … | … |
SP1A.211105.002.A1 | android-12.0.0_r9 | Android12 | Pixel 3a、Pixel 3a XL、Pixel 4、Pixel 4a、Pixel 4a (5G)、Pixel 4 XL、Pixel 5、Pixel 5a (5G) | 2021-11-05 |
说一下repo的下载,以下方式个人不建议:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
不建议的原因有:
基于上面两点,个人推荐使用tuna的git-repo镜像,下面我稍微修改了它的下载方式
1、
查看/usr/bin/或者/usr/local/bin是否有repo ,
如果有,请sudo cp /usr/bin/repo /usr/bin/repo_bak或者
sudo cp /usr/local/bin/repo /usr/local/bin/repo_bak
2、下载repo
sudo curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /usr/bin/repo
#sudo curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o /usr/local/bin/repo
#这样我就不用配置PATH环境变量了,因为本来PATH都包括/usr/local/bin/和/usr/bin,可以echo $PATH查看
sudo chmod +x /usr/bin/repo
3、执行repo命令进行下载源码(记得装git,python,不然执行会报错)
#不执行,会提示“Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle”
#可把该执行放到~/.bashrc环境变量中
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-12.0.0_r9
上面-b参数后面的android 版本号,可以点此查看,android-12.0.0_r9(SP1A.211105.002.A1) 该版本支持我自己手机的pixel 3a
4、repo sync -j2
步骤3执行完毕后,再执行该命令。
对于参数-j2,可以选择-j4,但是我试过了,-j2比-j4稳定多了。(-j4会经常卡住)
5、对于,个人选择一种笨的办法,以下是我的脚本,和网上不一样
每隔3小时,中断一次repo sync,但是,当提示repo sync has finished successfully,只能通过ps 查看该脚本运行pid,并且kill该sh的脚本运行
#!/bin/bash
while [ 1 ]; do
timeout 3h repo sync -j2
echo "======every 3h,inturept sync,then re-sync again======"
done
谷歌设备驱动下载
以下是我的手机pixel 3a的驱动文件下载
Pixel 3a binaries for Android 12.0.0 (SP1A.211105.002.A1)
Hardware Component | Company | Download |
---|---|---|
Vendor image | Link | |
GPS, Audio, Camera, Gestures, Graphics, DRM, Video, Sensors | Qualcomm | Link(这个不需要下载) |
然后你会得到一个tgz的压缩文件,把这个文件放到下载好的源码根目录,用tar -zxvf + 文件名,解压出来,得出一个sh文件,然后执行这个文件。我的是extract-google_devices-sargo.sh,执行命令为
./extract-google_devices-sargo.sh
其中在执行时,需要输入键盘ENTER和输入I ACCEPT
谷歌编译流程
android 12.0的源码编译时,需要一些第三方编译库和工具,参考官网提供的编译环境,罗列个人在编译android 12,android 11,android 10,android 9所需要编译库与工具
sudo apt install python -y
sudo apt install libswitch-perl -y
sudo apt install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib -y
sudo apt install git flex bison gperf build-essential libncurses5-dev:i386 -y
sudo apt install dpkg-dev libsdl1.2-dev libesd0-dev -y
sudo apt install git-core gnupg -y
sudo apt install zlib1g-dev gcc-multilib -y
sudo apt install libc6-dev-i386 -y
sudo apt install lib32ncurses5-dev x11proto-core-dev libx11-dev -y
sudo apt install libxml2-utils xsltproc m4 -y
sudo apt install lib32z-dev ccache -y
sudo apt install python-markdown zlib1g-dev:i386 -y
sudo apt install libssl-dev -y
sudo apt install android-tools-fastboot -y
sudo apt install android-tools-adb -y
注:
#如果安装过程中发现"无法定位软件包"字,可进行如下
sudo apt install vim
#在/etc/apt 的sources.list末端添加镜像源
sudo vim /etc/apt 的sources.list
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
sudo apt-get update
进行编译
source ./build/envsetup.sh
#Pixel 3a的产品代号为sargo
lunch aosp_sargo-userdebug
make update-api -j2 && make -j2
其中,在编译过程中,我用到-j4,-j8,老是提示内存不足,发现编译android 12需要快8G的内存,所以提高了VM的ubuntu的内存为8G,最后险编译通过
谷歌烧录教程
搭载ubuntu 系统的电脑通过USB连接设备pixel 3a
1、adb reboot bootloader(进行bootloader)
2、fastboot flashing unlock(不同设备OEM解锁,我在欧洲版Pixel 3a,bootloader是可以解锁的,至于其他设备的可以查看谷歌烧录教程)
3、source ./build/envsetup.sh(如果执行了,可以不用执行)
lunch aosp_sargo-userdebug(如果执行了,可以不用执行)
export ANDROID_PRODUCT_OUT=/home/fzc/study/android-12.0.0_r9/out/target/product/sargo(这个附上自己的源码pixel 3a代号sargo产物路径)
fastboot flashall -w
附上我成功烧录
android-12.0.0_r9$ fastboot flashall -w
--------------------------------------------
Bootloader Version...: b4s4-0.3-7357923
Baseband Version.....: g670-00116-210406-B-7261833
Serial Number........: 94LAY0QW31
--------------------------------------------
Checking 'product' OKAY [ 0.060s]
Setting current slot to 'a' OKAY [ 0.066s]
Sending 'boot_a' (65536 KB) OKAY [ 8.215s]
Writing 'boot_a' OKAY [ 0.430s]
Sending 'dtbo_a' (8192 KB) OKAY [ 1.100s]
Writing 'dtbo_a' OKAY [ 0.127s]
Sending 'vbmeta_a' (8 KB) OKAY [ 0.120s]
Writing 'vbmeta_a' OKAY [ 0.068s]
Rebooting into fastboot OKAY [ 0.060s]
< waiting for any device >
Sending 'system_a' (4 KB) OKAY [ 0.028s]
Updating super partition OKAY [ 0.054s]
Resizing 'product_a' OKAY [ 0.007s]
Resizing 'system_a' OKAY [ 0.006s]
Resizing 'system_ext_a' OKAY [ 0.013s]
Resizing 'vendor_a' OKAY [ 0.006s]
Resizing 'product_a' OKAY [ 0.006s]
Sending sparse 'product_a' 1/2 (262140 KB) OKAY [ 32.001s]
Writing 'product_a' OKAY [ 1.776s]
Sending sparse 'product_a' 2/2 (6948 KB) OKAY [ 0.891s]
Writing 'product_a' OKAY [ 0.133s]
Resizing 'system_a' OKAY [ 0.006s]
Sending sparse 'system_a' 1/4 (262140 KB) OKAY [ 31.700s]
Writing 'system_a' OKAY [ 1.845s]
Sending sparse 'system_a' 2/4 (262140 KB) OKAY [ 31.630s]
Writing 'system_a' OKAY [ 1.843s]
Sending sparse 'system_a' 3/4 (262140 KB) OKAY [ 32.274s]
Writing 'system_a' OKAY [ 1.876s]
Sending sparse 'system_a' 4/4 (25624 KB) OKAY [ 3.158s]
Writing 'system_a' OKAY [ 0.235s]
Resizing 'system_ext_a' OKAY [ 0.007s]
Sending 'system_ext_a' (126900 KB) OKAY [ 14.855s]
Writing 'system_ext_a' OKAY [ 0.997s]
Sending 'system_b' (72908 KB) OKAY [ 8.935s]
Writing 'system_b' OKAY [ 0.564s]
Resizing 'vendor_a' OKAY [ 0.005s]
Sending sparse 'vendor_a' 1/2 (262140 KB) OKAY [ 32.045s]
Writing 'vendor_a' OKAY [ 1.973s]
Sending sparse 'vendor_a' 2/2 (250144 KB) OKAY [ 30.937s]
Writing 'vendor_a' OKAY [ 1.780s]
Erasing 'userdata' OKAY [ 4.441s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Erasing 'metadata' OKAY [ 0.007s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Rebooting OKAY [ 0.003s]
Finished. Total time: 265.873s
注意: