野风技术札记 2019-06-27
具体参考官方文档
xcode-select --install
使用Homebrew安装(官方文档使用的是MacPorts)
brew install gmake libsdl git gnupg
_NOTE_: gmake 可以不用安装,使用xcode自带的就可以
在 ~/.bash_profile 添加如下语句
# set the number of open files to be 1024 ulimit -S -n 1024
官方文档创建的是区分大小写HFS+磁盘镜像,我们这边使用区分大小写的APFS卷宗
1. 打开磁盘工具按下图步骤操作:
2. 设置宗卷大小
具体大小根据自己情况设定,配额大小最好不要小于200G
具体参考官方文档-下载源码。
本文使用清华大学aosp镜像下载源码,具体步骤参考清华大学aosp镜像提供的教程。
mkdir ~/bin curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo chmod +x ~/bin/repo
在~/.bash_profile中将刚才创建的~/bin
目录添加进PATH
中
export PATH=~/bin:$PATH
mkdir WORKING_DIRECTORY cd WORKING_DIRECTORY
指定master分支
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
若要指定android版本,如下:
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-8.1.0_r20
repo sync
或者 repo sync -j4 # 指定并发数
NOTE: repo sync
有时会失败,可能要运行多次,才能同步完源码,可以使用以下循环脚本:
#!/usr/bin/env bash repo sync -j4 while [ $? -ne 0 ] do repo sync -j4 done
具体参考官方文档-编译源码
source build/envsetup.sh lunch aosp_x86_64-eng # 或者直接运行lunch, 在出现的选项中选择编译目标 make -j8 # 根据cpu核心数(物理线程)选择并发数,公式:并发数=cpu核心数(物理线程) x 2
编译过程比较漫长,在我的机子上大概用了2个多小时
internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12"]
[44/44] bootstrap out/soong/.minibootstrap/build.ninja.in
[4/4] out/soong/.bootstrap/bin/minibp out/soong/.bootstrap/build.ninja
[860/861] glob external/clang/utils/TableGen/Android.bp
[54/54] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
FAILED: out/soong/build.ninja
out/soong/.bootstrap/bin/soong_build -t -b out/soong -d out/soong/build.ninja.d -o out/soong/build.ninja Android.bp
internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12"]
ninja: build stopped: subcommand failed.
20:24:32 soong failed with: exit status 1
解决方法
修改AOSP/build/soong/cc/config/x86_darwin_host.go文件,添加10.13支持,如下
darwinSupportedSdkVersions = []string{ "10.10", "10.11", "10.12", "10.13", // 添加mac sdk 10.13 }
bison
错误FAILED: out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d --defines=out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h -o out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c external/selinux/checkpolicy/policy_parse.y
解决方法
为bison
打补丁,重新编译(Patch bison fix for High Sierra and build bison:):
cd AOSP/external/bison git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160 mm cp AOSP/out/host/darwin-x86/bin/bison AOSP/prebuilts/misc/darwin-x86/bison/
source build/envsetup.sh # 在新终端下需要执行这一步 mmma development/tools/idegen development/tools/idegen/idegen.sh
由于aosp工程很大,在导入IDEA前需要先修改配置:
-Xms1g -Xmx5g
修改文件大小限制,打开区分大小写选项
打开IDEA 菜单栏 Help -> Edit custom properties, 添加
idea.max.intellisense.filesize=100000 idea.case.sensitive.fs=true
NOTE: 重启IDEA使配置生效
NOTE 注意要删掉Classpath里面所有的jar
<Module source>
和 1.8 (No Libraries)
out/target/common/R
添加进源码目录,避免R资源索引找不到,如图: