官网 描述得已经至关清楚了 ,这里稍微总结一下:php
mac系统默认是不区分大小写的,因此咱们须要建立一个区分大小写的文件系统html
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g ~/android.dmg
复制代码
这将建立一个.dmg.sparseimage文件,该文件在装载后可用做具备 Android 开发所需格式的驱动盘。java
按官网所说完成编译至少须要 25GB 空间,相信我,其实至少须要60G。固然,空间大小后面还能够经过如下命令修改linux
hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage
复制代码
为了方便,咱们还能够往环境变量配置文件(~/.bash_profile
--bash,~/.zshrc
--zsh)添加辅助函数android
# mount the android file image
mountAndroid() { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;
复制代码
# unmount the android file image
umountAndroid() { hdiutil detach /Volumes/android; }
复制代码
JDKc++
各类 Android 版本使用的 Java 版本不同,请参阅相关要求git
我这里是编译Android8.1.0 ,因此使用java1.8shell
Xcode 命令行工具bootstrap
xcode-select --install
复制代码
MacPortsapi
从macports.org 下载安装,请确保 /opt/local/bin
在路径中显示在 /usr/bin
前面。不然,请将如下内容添加到环境变量配置文件(~/.bash_profile
--bash,~/.zshrc
--zsh)中:
export PATH=/opt/local/bin:$PATH
复制代码
经过 MacPorts 获取 Make、Git 、 GPG、BISON 软件包
POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg bison
复制代码
在 Mac OS 中,可同时打开的文件描述符的默认数量上限过低,在高度并行的编译流程中,可能会超出此上限。要提升此上限,请将下列行添加到环境变量配置文件(~/.bash_profile
--bash,~/.zshrc
--zsh)中:
# set the number of open files to be 1024
ulimit -S -n 1024
复制代码
Android 源代码树位于由 Google 托管的 Git 代码库中。为了在 Android 环境中更轻松地使用 Git,Google开发了Repo。
bin/
目录,而且该目录包含在路径中:mkdir ~/bin
PATH=~/bin:$PATH
复制代码
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
复制代码
➜ ~ mountAndroid
/dev/disk3 GUID_partition_scheme
/dev/disk3s1 EFI
/dev/disk3s2 Apple_HFS /Volumes/android
➜ ~ cd /Volumes/android
➜ ~ mkdir aosp
➜ ~ cd aosp
复制代码
repo init -u https://android.googlesource.com/platform/manifest -b android-8.1.0_r50
复制代码
初始化成功后,目录中应包含一个 .repo
目录。
这时候就能够开始漫长的下载过程了
repo sync
复制代码
同步操做顺利的话将须要 1 个小时或更长时间完成,
从官网下载对应机型驱动便可,下载完成后解压,依次执行里面的sh文件,如:
$ ./extract-huawei-angler.sh
The license for this software will now be displayed.
You must agree to this license before using this software.
Press Enter to view the licensels
复制代码
执行完毕,驱动文件会释放到vendor目录。
make clobber
复制代码
source build/envsetup.sh
复制代码
➜ ~ lunch
You're building on Darwin
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. aosp_deb-userdebug
8. aosp_flo-userdebug
9. full_fugu-userdebug
10. aosp_fugu-userdebug
11. mini_emulator_arm64-userdebug
12. m_e_arm-userdebug
13. mini_emulator_mips-userdebug
14. mini_emulator_x86-userdebug
15. mini_emulator_x86_64-userdebug
16. aosp_flounder-userdebug
17. aosp_angler-userdebug
18. aosp_bullhead-userdebug
19. aosp_hammerhead-userdebug
20. aosp_hammerhead_fp-userdebug
21. aosp_shamu-userdebug
22. aosp_bullhead-userdebug
23. aosp_angler-userdebug
复制代码
由于我要编译nexus6p,这里选择23,其余设备能够参考选择设备编译系统
make -j8
复制代码
-jN
表示编译并行任务数,这个示电脑状况而定,通常取cpu数的1~2倍就能够
[44/44] bootstrap out/soong/.minibootstrap/build.ninja.in
[4/4] out/soong/.bootstrap/bin/minibp out/soong/.bootstrap/build.ninja
[860/861] glob vendor///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.
17:53:06 soong failed with: exit status 1
复制代码
解决方法
修改/build/soong/cc/config/x86_darwin_host.go文件,添加10.14支持,以下
darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.14", // 添加mac sdk 10.14
}
复制代码
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
[ 0% 309/87784] //external/libcxx:libc++_static header-abi-dumper src/random.cpp [arm]
ninja: build stopped: subcommand failed.
18:05:05 ninja failed with: exit status 1
复制代码
cd /Volumes/AOSP/external/bison
git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160
mm
# 用新生成的bison替换掉原bison文件
cp /Volumes/AOSP/out/host/darwin-x86/bin/bison /Volumes/AOSP/prebuilts/misc/darwin-x86/bison/
# 从新编译
make -j8
复制代码
通过漫长的等待和反复折腾后,终于到了最后一步---刷机。
# 手机链接电脑状况下
adb reboot bootloader
# 进入源码编译输出的目录
fastboot flashing unlock
fastboot flashall -w
复制代码
参考连接