内容简介:mac系统默认是不区分大小写的,所以我们需要创建一个区分大小写的文件系统这将创建一个.dmg.sparseimage文件,该文件在装载后可用作具有 Android 开发所需格式的驱动盘。按官网所说完成编译至少需要 25GB 空间,相信我,其实至少需要60G。当然,空间大小后面还可以通过以下命令修改
mac系统默认是不区分大小写的,所以我们需要创建一个区分大小写的文件系统
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g ~/android.dmg 复制代码
这将创建一个.dmg.sparseimage文件,该文件在装载后可用作具有 Android 开发所需格式的驱动盘。
按官网所说完成编译至少需要 25GB 空间,相信我,其实至少需要60G。当然,空间大小后面还可以通过以下命令修改
hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage 复制代码
为了方便,我们还可以往环境变量配置文件( ~/.bash_profile
--bash, ~/.zshrc
--zsh)添加辅助函数
- 装载函数
# mount the android file image
mountAndroid() { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;
复制代码
- 卸载函数
# unmount the android file image
umountAndroid() { hdiutil detach /Volumes/android; }
复制代码
安装所需的软件
-
JDK
各种 Android 版本使用的 Java 版本不一样,请参阅相关要求
我这里是编译Android8.1.0 ,所以使用java1.8
-
Xcode 命令行工具
xcode-select --install 复制代码
-
MacPorts
从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。
安装 Repo
-
确保主目录下有一个
bin/目录,并且该目录包含在路径中:
mkdir ~/bin PATH=~/bin:$PATH 复制代码
- 下载 Repo 工具,并确保它可执行
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo chmod a+x ~/bin/repo 复制代码
repo 初始化
进入我们一开始创建的文件系统,创建一个空目录
➜ ~ mountAndroid /dev/disk3 GUID_partition_scheme /dev/disk3s1 EFI /dev/disk3s2 Apple_HFS /Volumes/android ➜ ~ cd /Volumes/android ➜ ~ mkdir aosp ➜ ~ cd aosp 复制代码
指定需要checkout对应的源代码标记和编译版本
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倍就可以
编译遇到问题
找不到对应的macOS.sdk
- 报错日志
[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
}
复制代码
遇到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 [ 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 复制代码
以上所述就是小编给大家介绍的《Mac 10.14 编译Android 8.1源码及刷入nexus 6p》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Golang源码探索(一) 编译和调试源码
- 写Java这么久,JDK源码编译过没?编译JDK源码踩坑纪实 原 荐
- JVM源码分析-JVM源码编译与调试
- 使用源码编译Hadoop
- Runtime源码编译
- 下载编译AOSP源码
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
算法心得:高效算法的奥秘(原书第2版)
(美)Henry S. Warren, Jr. / 爱飞翔 / 机械工业出版社 / 2014-3 / 89.00
【编辑推荐】 由在IBM工作50余年的资深计算机专家撰写,Amazon全五星评价,算法领域最有影响力的著作之一 Google公司首席架构师、Jolt大奖得主Hoshua Bloch和Emacs合作创始人、C语言畅销书作者Guy Steele倾情推荐 算法的艺术和数学的智慧在本书中得到了完美体现,书中总结了大量高效、优雅和奇妙的算法,并从数学角度剖析了其背后的原理 【读者评价......一起来看看 《算法心得:高效算法的奥秘(原书第2版)》 这本书的介绍吧!