安卓源码AOSP下载使用的正确姿势

从同步源码到编译完成,整个过程应至少准备200G空间。

编译时需要的内存数与编译线程数相关,博主实测比较极限的配置是4核8G,超过这个范围将触发swap交换导致编译速度急剧下降。

开始搞,注:以下*号所有内容替换成G00gle,至于为什么连单词都写错了你懂的。

0x01 前置准备

# 下载repo
sudo apt-get install repo# 下载git并设置用户名邮箱
sudo apt-get install git
git config --global user.name "bryan sun"
git config --global user.email "hitsjt@gmail.com"# 挑选需要同步的AOSP分支
https://source.android.*.cn/setup/build-numbers# 配置全局git加速
git config --global url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof https://android.*source.com
git config --global url."https://hub.fastgit.org".insteadOf https://github.com
# 取消全局配置
# git config --global --unset http.proxy# 三行科普repo是个什么东西
当有了版本控制思想,你用上了git。
aosp由几百个git子项目组成,如果需要每个子项目都让你手动去挑选版本分支,然后git pull估计得崩溃。
repo作为git的控制封装脚本,可以对每个安卓分支版本需要搭配什么git子项目进行列表配置,随后批量操作这些git子项目,这就是为什么*设计了repo,一切为了操作便捷。
*在同步源码时查看文件.repo/manifests/default.xml能更好体会# 一把安装环境
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc -y
sudo apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev -y# oracle jdk8
# https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_271/bin/java 180271
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_271/bin/javac 180271
update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.8.0_271/bin/javadoc 180271# openjdk8
# https://www.openlogic.com/openjdk-downloads
# 链接: https://pan.baidu.com/s/1cNtYW-bbqDEPQf8IGIk0Jw 提取码: ghdv openjdk-8u272
# 链接: https://pan.baidu.com/s/1r85kLAipjWZxG9DUaKo7sA 提取码: k9r8 openjdk-8u262
update-alternatives --install /usr/bin/java java /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/bin/java 180272
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/bin/javac 180272
update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/bin/javadoc 180272# 虚拟机设置,真机不用理会
apt-get install open-vm-tools-desktop fuse  # 安装vmware-tools
mkdir -p /mnt/hgfs/VMShare  # 创建挂载目录
/usr/bin/vmhgfs-fuse .host:/VMShare /mnt/hgfs/VMShare -o subtype=vmhgfs-fuse,allow_other  # 挂载共享目录,host指定的名字就是虚拟机共享目录的名字# 设置开机自动挂载
gedit /etc/systemd/system/rc-local.service
[Unit]Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.local[Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0StandardOutput=ttyRemainAfterExit=yesSysVStartPriority=99[Install]WantedBy=multi-user.targetgedit /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.sudo /usr/bin/vmhgfs-fuse .host:/VMShare /mnt/hgfs/VMShare -o subtype=vmhgfs-fuse,allow_otherexit 0chmod 755 /etc/rc.local  # 设置执行权限
systemctl enable rc-local.service  # 开启rc.local开机自启动服务
systemctl is-active rc-local.service  # 查看服务状态
systemctl restart rc-local.service  # 重启服务

0x02 获取AOSP源码包

# 方法1.通过下载TUNA完整增量月包,下载完后解压只需要简单操作就能获得大部分源码,剩下的同步只需要少量操作即可完成
# 博主未完整实测,下一半挂了,逼着用完整同步
https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar.md5
# 解压后得到.repo文件夹,在根目录repo sync即可迁出文件
# 如果repo sync操作出现源代码被改动提示可以用以下命令修复
repo sync -d                         # 将所有git 仓库的HEAD重置为manifest文件的指定版本
repo forall -c 'git reset --hard'    # Remove all working directory (and staged) changes.
repo forall -c 'git clean -f -d'     # Clean untracked files# 方法2.同步完整的源码
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/ -b android-8.1.0_r15
# 开始同步
repo sync -c -f --no-tags --no-clone-bundle -j4-c 或者--current-branch表示只拉取当前分支代码,坑爹啊,我在init指定了分支,同步的时候,你却悄悄给我拉些没用的。
--no-tags 不拉取tags,tag虽然不大,但架不住多
--no-clone-bundle 不使用clone.bundle,clone.bundle是git bundle一样的打包文件,使用bundle文件可以做cdn下载的分流,cdn听上去不错,但是如果cdn到google的服务器,或者clone.bundle本来就占空间,不是很划算,所以不使用clone.bundle
-f 如果sync失败,继续同步
--force-sync 如果文件目录有差异,强制覆盖掉# 附赠一个git只克隆当前分支的办法,和指定分支无关的部分将不会克隆
git clone -b mybranch --single-branch git://sub.domain.com/repo.git# 使用7z最高压缩比打包源码
7za a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on yourfile.7z yourfile &

0x03 切换不同版本的AOSP

# 将repo配置重新指定为相关版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/ -b android-6.0.1_r67# rm -rf有个特性不会删除隐藏目录,切换版本操作也就是只需要保留.repo目录
rm -rf *# 再次同步即可
repo sync# 查看分支列表
cd .repo/manifests
git branch -av# 其中分支代码也可以在这里查
https://blog.csdn.net/bt_leo/article/details/78706608

0x04 编译模拟器版本aosp并用模拟器测试

# 基于android6.0.1, Ubuntu 16.04 LTS# 安装openjdk7,oracle java7不能被aosp识别所以不用
sudo add-apt-repository ppa:openjdk-r/ppa
# 20200419再次使用发现执行失败,进而Error: retrieving gpg key timed out.
# 然后通过你懂的方式上网就行了,Ubuntu这年头都能墙,某网部你牛逼
sudo apt-get update
sudo apt-get install openjdk-7-jdk  // OpenJdk 7安装# 跳过CCLANG的一个不兼容选项,博主实际编译也遇到过
# 如果不修改的话会在编译libart.so的时候error停下。
修改 art/build/Android.common_build.mk 文件,定位到77行
将:
ART_HOST_CLANG := true
改为:
ART_HOST_CLANG := false# 设置高速编译启用标志位(占硬盘,空间小可以不执行,空间换时间)
echo export USE_CCACHE=1 >> ~/.bashrc
aosp/prebuilts/misc/linux-x86/ccache/ccache -M 50G# 导入编译环境
source build/envsetup.sh# 设置编译选项
# lunch aosp_sailfish-user
lunch# 开干,-j参数为编译线程数,幸运的话睡一觉起来就OK啦。
sudo make -j4# 一键设置环境变量(该命令由build/envsetup.sh导入)
set_stuff_for_environment# 进入安卓源码编译生成目录
cd out/target/product/generic# 启动模拟器
emulator

0x05 编译真机并刷入

# 在官方下载驱动组件包,放在安卓源码根目录解压后运行sh脚本即可,其他流程与普通编译一致
https://developers.*.com/android/drivers# 设置最终ROM包的编译签名为release
https://source.android.com/devices/tech/ota/sign_builds
gedit build/make/core/Makefile
BUILD_KEYS := release-keys# 刷机
export ANDROID_PRODUCT_OUT=/root/Desktop/aosp/android10.0_r17.QP1A.191005.007.A3/out/target/product/sailfish
fastboot flashall -w

0x06 集成opengapps

# 为了在AOSP上能使用G* Play,可以选择直接集成opengapps,这样编译后刷入就能有套装
# 官方已给详细步骤说明,不再另外单独记录
# 值得一说的是各设备的配置文件路径会稍有差别,例如pixel在安卓10下路径为device/google/marlin/device-sailfish.mk
https://github.com/opengapps/aosp_build# Product cannot have overlay in vendor tree
# gedit device/lge/bullhead/aosp_bullhead.mk
# PRODUCT_RESTRICT_VENDOR_FILES := false

0x07 跳过Factory image联网验证

重新启动后联网处即可出现跳过选项

fastboot erase frp

参考资料

[Android 编译(一)] Ubuntu 16.04 LTS 成功编译 Android 6.0 源码教程_fuchaosz的博客-CSDN博客_ubuntu 编译android

AOSP | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

repo 工具使用手册_counsellor的博客-CSDN博客_repo sync 参数

安卓源码AOSP下载使用的正确姿势相关推荐

  1. ubuntu系统下安卓源码的下载

    以前可以采用git clone方法下载Android单个目录源码的方法,但是目前Google对源代码的管理网站已经进行了更改,直接采用下载源代码已经失效.本文介绍了在Ubuntu下(在Windows下 ...

  2. AOSP安卓源码下载

    Android源码下载 在国内想下载Android要么科学上网,要么使用国内搭建的镜像,有清华镜像,中科大的镜像网站.这里使用清华镜像网站镜像Android源码的下载清华镜像网站地址,为啥我要写这篇笔 ...

  3. 安卓源码(一)下载与同步

    推荐系统:基于Debian8的Linux发行版,ubuntu16.04,(因为安卓源码实在ubuntu下编译的,redhat系没有) 我使用的系统:Deepin15.3(ubuntu是debian8 ...

  4. 最新安卓例子分类源码打包下载

    [原文:http://www.javaapk.com/demodownload] 废话少说,直戳重点.源码最新下载地址: http://yunpan.cn/QTptFRNMIJpeQ 访问密码 381 ...

  5. 下载安卓源码都干了什么?

    闲来无事,想瞅瞅安卓wifi的框架是什么样子滴,就有了如下的记录 目录 1.准备linux系统 2.创建samba共享目录 4.下载源码 5.下载repo 6.同步代码 7.完成同步,开始阅读 1.准 ...

  6. AOSP 安卓源码7.1

    Q1.首次编译报错(Ubuntu14.04-Android6.0) Log: ERROR: Bad request, see Jack server log (/tmp/jack-envy15/jac ...

  7. AOSP 安卓源码7.1-ubuntu17.04编译问题

    Q1.首次编译报错(Ubuntu14.04-Android6.0) Log: ERROR: Bad request, see Jack server log (/tmp/jack-envy15/jac ...

  8. 安卓编译安装python_安卓源码编译环境搭建

    本编译环境以 Ubuntu 14.04 系统为例 修改软件源(可选) 安装相关依赖 安装Android编译工具JDK 一. 修改软件源(可选) : sudo gedit /etc/apt/source ...

  9. mac下编译安卓源码

    资源 Mac OS10.12 编译Android源码8.1 aosp编译-需翻墙 Mac下编译安卓源码 手把手教你在Mac OS下载.编译及导入Android源码 步骤 准备 磁盘空间大于180G 安 ...

最新文章

  1. liunx的目录结构
  2. POJ 2336 Ferry Loading II 动态规划
  3. 卷积神经网络(CNN)
  4. 实验7.2 二维数组 7-8 螺旋方阵
  5. 知识图谱的概念、应用与构建
  6. [WPF]有Focus(), 那Unfocus()呢?
  7. 服务器串口协议,基于TCPIP协议串口通信服务器设计说明.docx
  8. 《构建之法》阅读笔记(三)
  9. 鼎利测试软件 说明书,鼎利软件使用手册.docx
  10. Python兼职:300-800元/天,各行各业都能运用!
  11. 计算机flops测试,谁知道哪个软件可以测试CPU是多少GFLOPS?
  12. iGoogle自定义
  13. InputStreamReader乱码
  14. 微信小程序-打开地图选择位置
  15. python批量下载txt图片批量导入到ppt
  16. 右键新增文件/文件夹-打开方式
  17. python混淆矩阵,详解使用python绘制混淆矩阵(confusion_matrix)
  18. 计算机cpu的字母,买电脑如何识别CPU后面数字和字母的含义?不被忽悠呢?
  19. 为miniconda设置环境变量
  20. AC、HC、AHC、ACT、LS的区别

热门文章

  1. Ubuntu下安装日语输入法
  2. 软工专硕考研_你可能需要了解--2018年北京大学软微软件工程专硕考研 经验分享...
  3. 绿幕背景视频抠图替换
  4. 相机光学(十一)——镜头
  5. 阅读笔记04——魔鬼搭讪学
  6. 为了下一代,抖音真的该关了---读<<我观察到的牛人有这三个特质>>有感
  7. 三段论_五项基本原则
  8. 嵌入式RTSP转RTMP设备说明
  9. pythonweb项目微服务_python web微服务器端
  10. 数据结构与算法Python版-第六周作业