Android12 源码编译及刷写Piexl6设备


捣鼓了一个多星期Android12源码编译到刷写Pixel6设备,由于公司硬件环境限制和源码太大,中间浪费了很多时间,编译前一定要准备好硬件环境,不然事倍功半

一、硬件要求

  • cpu:需要 64 位环境

  • 内存:至少需要 16 GB 的可用 RAM,但 Google 建议提供 64 GB

  • 硬盘空间:如果要检出代码,至少需要 250 GB 可用磁盘空间;如果要进行构建,则还需要 150 GB。如果要进行多次构建,则需要更多空间。

    内存空间如果不够,可以通过增加swap空间的方法来解决,但是在windows中Ubuntu子系统试过不行

二、软件要求

  • 操作系统:Ubuntu (LTS) 版本,不支持 MacOS 或 Windows
  • 使用python3
  • 所需的软件包
  1. 安装所需的软件包 (Ubuntu 18.04)
    64 位版本的 Ubuntu

    sudo apt-get install 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

  2. 安装所需的软件包 (Ubuntu 14.04)
    64 位版本的 Ubuntu

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

三、源码下载

1. 安装repo

repo是Android为了方便管理多个git库而开发的Python脚本。repo的出现,并非为了取代git,而是为了让Android开发者更为有效的利用git。Android源码包含数百个git库,仅仅是下载这么多git库就是一项繁重的任务,所以在下载源码时Android就引入了repo。
repo命令参考:https://source.android.google.cn/setup/develop/repo?hl=zh-cn

repo工具下载并添加执行权限
> mkdir ~/bin

PATH=~/bin:$PATH
curl -sSL ‘https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT’ |base64 -d > ~/bin/repo
chmod a+x ~/bin/repo

2. 下载源码

  • 由于国内不能访问Android仓库,建议使用清华源下载Android源代码,两种修改方式使用清华源:
  1. 修改repo脚本,将~/bin/repo文件里面的REPO_URL的值修改为"https://mirrors.tuna.tsinghua.edu.cn/git/git-repo"
  2. 在~/.bashrc文件里面增加一条配置:REPO_URL = ‘https://mirrors.tuna.tsinghua.edu.cn/git/git-repo’
  • 开始下载源码
  1. 创建源码根目录
    在本地建一个目录,名字任意,如下

    mkdir android12
    cd android12

  2. 初始化仓库
    初始化仓库有两种方式,第一种是直接下载,这种方式会下载所以分支代码;第二种下载特定tag的版本,这种方式下载的是Android的某一个版本,具体如下:

    1. 直接下载方式,这种方式占用磁盘空间比较大,下载时间比较长,不太建议,初始化方法如下:

      repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest

    2. 下载特定tag的方式,首先确定需要下载的Android版本,比如需要下载pixel6对应的Android12最新版本,从Android官网查看Android版本对应的tag,如下:
      官网网址:https://source.android.google.cn/setup/start/build-numbers#source-code-tags-and-builds
      在这里插入图片描述
      从中可以看出对应的tag为android-12.1.0_r11,初始化方法如下:

      repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-12.1.0_r11

    注:初始化仓库前如果没有配置git相关信息则会报错,报错后配置一下git,在重新按上面的步骤初始化即可

  3. 同步代码
    初始化完成后即可同步代码

    repo sync -j4

    -j4表示启用4个线程来同步代码,sync的时候并发数不宜太高,建议选择4

四、真机驱动下载

在Google手机上刷机时需要下载Google硬件驱动,初始化仓库方式不同,下载的驱动也不同

  1. 将下载的驱动压缩包拷贝的Android源码根目录,并进行解压,解压后得到一个.sh的脚本
    在这里插入图片描述
    解压命令

    tar -zxvf google_devices-oriole-sp2a.220305.013.a3-04c512f4.tgz

  2. 执行extract-google_devices-oriole.sh脚本提取驱动

    ./extract-google_devices-oriole.sh

    在这里插入图片描述

    运行提示"Press Enter to view the license"时输入回车后即可,后面输入d来进行翻页

    在这里插入图片描述

    直到提示输入"I ACCEPT"时,按提示输入后回车即可完成驱动的提取,完成后源码根目录多了一个vendor的目录

    在这里插入图片描述

五、编译

  1. 设置代码编译环境,每次重启shell时都需要配置编译环境,在根目录执行如下命令:

    source build/envsetup.sh

    . build/envsetup.sh

    执行build/envsetup.sh脚本后则在环境中配置几个shell命令,后续即可使用这些命令选择设备目标和编译,输入hmm命令即可查看完整的命令列表:

    - 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.
    
  2. 使用lunch命令选择设备目标

    如果输入lunch命令列出的设备目标中没有上面的设备目标,则直接输入上面的设备目标即可

  3. 开始编译,输入m或make即可编译整个Android源码,也可使用参数-j指定线程数

    m

    如果只编译某一部分,则先切换的对应的目录下,使用mm命令进行编译

六、刷机

  • Android模拟设备,输入emulator命令即可启动Android模拟器
  • Pixel真机刷机
  1. window系统下载adb和fastboot工具
    下载链接:https://developer.android.google.cn/studio/releases/platform-tools#downloads
    解压后将目录添加到环境变量中

  2. 手机上启动USB调试
    - 如要在通过 USB 连接的设备上使用 adb,则必须在设备的系统设置中启用 USB 调试(位于开发者选项下)
    - “开发者选项”屏幕默认情况下处于隐藏状态,如需将其显示出来,请依次转到设置 > 关于手机,然后点按版本号七次就会提示"You are now a developer!"
    - 再依次转到设置 > 系统 > 开发者选项里面,可以开启USB调试
    - 此时如果没有安装Google的usb驱动,在设备管理器里面找不到"Android Device"设备,adb reboot bootloader进入fastboot模式之后,输入fastboot devices命令找不到设备

  3. 安装驱动
    下载链接:https://developer.android.google.cn/studio/run/win-usb
    在设备管理器中找到对应的设备安装驱动,安装好后则会多出一个"Android Device"设备
    在这里插入图片描述

  4. 解锁加载引导程序
    - 在cmd中输入"adb reboot bootloader"进入fastboot模式,查看是否处于锁定模式
    - 如果处于锁定模式则输入"fastboot flashing unlock"进行解锁,同时需要在手机上进行确认
    - 处于解锁模式后,设备每次启动都会先进入fastboot模式,如需处于锁定模式,则输入"fastboot flashing lock"命令

  5. 刷写设备
    - 在cmd中输入"adb reboot bootloader"进入fastboot模式
    - 切换到Android镜像目录,输入"fastboot flashall -w"命令即可将镜像刷写到设备中,刷写完成等待设备重启就是运行的原生Android系统了

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
刷写PX4固件的过程包括刷写bootloader和刷写PX4固件本身。刷写bootloader是为了将设备进入fastboot模式,然后再切换到Android镜像目录,通过命令将镜像刷写设备中。具体操作如下: 1. 使用命令行工具(如cmd)输入"adb reboot bootloader",使设备进入fastboot模式。 2. 切换到Android镜像目录,执行"fastboot flashall -w"命令,将镜像刷写设备中。刷写完成后等待设备重启,即可运行原生Android系统。 关于刷写PX4固件部分,可以按照以下步骤进行操作: 1. 按照指导设置好刷写环境,点击右下角加载固件。 2. 在加载固件时选择最新的f4bl固件,并点击下载。下载完成后拔掉USB连接线。 总结起来,刷写PX4固件包括刷写bootloader和刷写PX4固件本身。刷写bootloader的过程是通过命令将设备进入fastboot模式,并将镜像刷写设备中。刷写PX4固件的过程是根据指导设置好环境,选择最新的固件并下载,然后拔掉USB连接线。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Android12 编译刷写Piexl6设备](https://blog.csdn.net/Jian_0216/article/details/126020486)[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: 50%"] - *2* *3* [PX4装机教程(四)F4飞控刷写PX4](https://blog.csdn.net/qq_38768959/article/details/106988811)[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: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值