Android 12 源码下载、编译与烧录到Pixel 3a

当前设备环境

操作系统: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.A8android-12.0.0_r13Android12Pixel 6、Pixel 6 Pro2021-11-05
SP1A.211105.002.A1android-12.0.0_r9Android12Pixel 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

不建议的原因有:

  1. PATH=~/bin:$PATH 只在当前Terminal有效果,你重新打开另个一个Terminal,又得重新输入PATH=~/bin:$PATH,才可以使用repo,当然,你可以将~/bin增加ubuntu的环境变量
  2. 用repo init 命令时,没有科学上网会提示无法连接到 gerrit.googlesource.com.

基于上面两点,个人推荐使用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 ComponentCompanyDownload
Vendor imageGoogleLink
GPS, Audio, Camera, Gestures, Graphics, DRM, Video, SensorsQualcommLink(这个不需要下载)

然后你会得到一个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

注意

  1. 烧录成功却无法正常开机,请检查谷歌手机设备驱动的下载是否错误。
  2. 烧录成功却无法正常开机,你可以去官网烧录将设备的出厂镜像(factory images),以便你正常开机使用
  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
下载编译Android源码,首先需要安装好git和repo等工具。你可以参考《Android源码下载 & 编译(高通)》第1节中的指南来完成这些工具的安装过程。 下载Android源码的方法可以根据不同的情况而有所不同。如果你是按照《Android源码下载 & 编译(高通)》的方法下载源码,那么源码中应该包含有kernel目录,也就是包含了Linux内核。然而,通过其他方法下载源码可能不包含kernel目录,也就是没有包含Linux内核。在参考资料中明确指出,Android 4.0源码默认下载是不包括内核源码的。因此,如果你遇到这种情况,你需要另外下载Android和Linux源码,并进行编译。 需要注意的是,与《Android源码下载 & 编译(高通)》不同,上述编译过程并没有编译Linux内核。你需要按照下文的指引进行Linux内核的编译。具体的步骤和方法可以参考后续的文档。 总结起来,要下载编译Android源码,你需要先安装好相关工具,然后根据具体的情况选择合适的下载方法。如果你已经按照《Android源码下载 & 编译(高通)》的方法下载源码,那么你已经包含了Linux内核。否则,你需要额外下载Android和Linux源码,并按照相关指引进行编译。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Android源码下载&编译(TI)](https://blog.csdn.net/Q1302182594/article/details/52208366)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值