AOSP下载编译并刷机最新分步骤详解
我的环境
Ubuntu 18.04.5 LTS
清华源
https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
安装repo, 3种方式
# 1. 无需安装, 下载初始化包中自带最好用
# 2. ubuntu apt-get
sudo apt-get install repo
# 3. 单独脚本的方式(不推荐, 至少在我的电脑上, 会报一些python脚本兼容性错误, 手动改了又会遇到uncommit change错误)
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo
使用每月更新的初始化包
# 下载初始化包, 查看包列表 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/, 由于最新包太大了, 我只需要Android-8.0的包
wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-20190101.tar
# 或下载最新包8-90G吧 wget -c https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 解压得到的 AOSP 工程目录 tar xf aosp-latest.tar cd AOSP # 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
# 正常同步一下,即可得到完整目录 repo sync # 或 repo sync -l 仅checkout代码(这种方式比较快,不会fetch最新的远程仓库,也就是如果我下载的是20190101.tar,则最新的修改就到这天,之后至今天的修改,不同步.)
# 如果不加 -l 选项, 则更新本地仓库为最新上百G了.
查看分支列表
# 进入Repo目录,查看所有分支 cd .repo/manifests git branch -a
# 如果像我一样使用repo sync -l选项同步, 会发现分支最新只到android-9.0
切换到需要的目标分支
查看 https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds 找到你想使用的分支, 这里我选择 android-8.1.0_r35 , 原谅我手上只有一台Pixel 2. 所以要选择支持我这台设备的分支, 为后续刷机作准备
# 切换分支 repo init -b android-8.1.0_r35
如果提示无法连接到 gerrit.googlesource.com,请参照git-repo的帮助页面的更新一节。
环境配置
sudo apt-get update sudo apt-get install openjdk-8-jdk
# 安装必要程序包 (我就不装)
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
编译
source build/envsetup.sh
lunch aosp_arm64-eng
# 若想查看所有lunch选项, 可以输入lunch 回车
我们先编译一个模拟器版的, 因为AOSP缺少vendor目录, 即不包含实体设备的驱动
输入2 回车, 接下来
make -j8 # 我的电脑是4核8线程的, 一次全编 它可以从早编到晚 ~~
不出意外会编译成功. 看下输出目录, 会有各种img
ls $OUT
编译完成后可以运行模拟器看下效果
emulator
关于lunch构建目标
构建类型 | 说明 |
user | 权限受限;适用于生产环境 |
userdebug | 与“user”类似,但具有 root 权限和调试功能;是进行调试时的首选编译类型 |
eng | 具有额外调试工具的开发配置, 会关闭用于提供良好用户体验的各种优化 |
有意外发生 ~
遇到的错误
# 报python语法错误
acer@acer-TravelMate-P249-G3-MG:~/aosp-test/aosp$ repo sync -l Traceback (most recent call last): File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 198, in GetBranch b = self._branches[name] KeyError: 'default' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 531, in <module> _Main(sys.argv[1:]) File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 507, in _Main result = repo._Run(argv) or 0 File "/home/acer/aosp-test/aosp/.repo/repo/main.py", line 158, in _Run copts, cargs = cmd.OptionParser.parse_args(argv) File "/home/acer/aosp-test/aosp/.repo/repo/command.py", line 67, in OptionParser self._Options(self._optparse) File "/home/acer/aosp-test/aosp/.repo/repo/subcmds/sync.py", line 189, in _Options self.jobs = self.manifest.default.sync_j File "/home/acer/aosp-test/aosp/.repo/repo/manifest_xml.py", line 360, in default self._Load() File "/home/acer/aosp-test/aosp/.repo/repo/manifest_xml.py", line 400, in _Load b = m.GetBranch(m.CurrentBranch).merge File "/home/acer/aosp-test/aosp/.repo/repo/project.py", line 814, in GetBranch return self.config.GetBranch(name) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 200, in GetBranch b = Branch(self, name) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 725, in __init__ self.merge = self._Get('merge') File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 768, in _Get return self._config.GetString(key, all_keys = all_keys) File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 131, in GetString v = self._cache[_key(name)] File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 248, in _cache self._cache_dict = self._Read() File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 254, in _Read d = self._ReadGit() File "/home/acer/aosp-test/aosp/.repo/repo/git_config.py", line 299, in _ReadGit for line in d.decode('utf-8').rstrip('\0').split('\0'): # pylint: disable=W1401 AttributeError: 'str' object has no attribute 'decode'
解决办法: 试试用 .repo/repo/repo sync -l
# 遇到错误 [490/999] including ./hardware/qcom/keymaster/Android.mk ... [491/999] including ./hardware/qcom/media/Android.mk ... hardware/qcom/media/msm8998/mm-video-v4l2/vidc/venc/Android.mk:60: warning: "venc: PQ compiled out" [492/999] including ./hardware/qcom/msm8998/Android.mk ... including hardware/qcom/msm8998/gpt-utils/Android.mk ... including hardware/qcom/msm8998/json-c/Android.mk ... including hardware/qcom/msm8998/thermal-engine/Android.mk ... including hardware/qcom/msm8998/time-services/Android.mk ... [493/999] including ./hardware/qcom/power/Android.mk ... [494/999] including ./hardware/qcom/sdm845/Android.mk ... ./hardware/qcom/power/Android.mk:3: error: ./hardware/qcom/sdm845/Android.mk: No such file or directory 15:33:38 ckati failed with: exit status 1
解决: 进入hardware/qcom/sdm845, ls -l 可见一些无效的符号链接, 直接删除即可
[ 7% 7944/104967] Ensuring Jack server is installed and started FAILED: setup-jack-server /bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 4.11.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.32.CANDIDATE.jar 4.32.CANDIDATE || exit 47 )" Writing client settings in /home/admz/.jack-settings Installing jack server in "/home/admz/.jack-server" Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /home/admz/.jack-server/server.jks -destkeystore /home/admz/.jack-server/server.jks -deststoretype pkcs12". Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /home/admz/.jack-server/client.jks -destkeystore /home/admz/.jack-server/client.jks -deststoretype pkcs12". Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /home/admz/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log SSL error when connecting to the Jack server. Try 'jack-diagnose' SSL error when connecting to the Jack server. Try 'jack-diagnose' ninja: build stopped: subcommand failed. 15:22:28 ninja failed with: exit status 1 #### failed to build some targets (06:57 (mm:ss)) ####
解:
$ sudo vim /etc/java-8-openjdk/security/java.security
将
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \ DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ include jdk.disabled.namedCurves
从 jdk.tls.disabledAlgorithms 删除 TLSv1, TLSv1.1,
重启jack-server
$ cd prebuilts/sdk/tools/
$ ./jack-admin kill-server
$ ./jack-admin start-server
参考:
https://source.android.com/source/initializing
https://source.android.com/docs/setup/build/building