前言

背景

工作需要,想着刚好有个趁手的兵器(Mac),虽然做好充足的功课,但是这场编译之旅还是十分曲折

本文主要记录本人使用macOs( 10.14) 在本地 checkout 出 AOSP ,并进行编译,导入 Android Studio 的完整经历。

安装软件

  1. XCode : 编译源码需要
  2. MacOSX-SDK (10.13) : 编译需要。本机是10.14 版本,有问题,详细见碰到的问题二,
  3. JDK : 一般都有,没有要装下
  4. MacPorts : 下载工具,用来下载编译源码需要的软件

正文

Mac 分区

为何分区:

  1. Linux 文件名大小写敏感,
  2. mac 默认文件系统大小写不敏感,编译系统会报错

如何分区:

  1. 磁盘工具(Disk Utility)-> 分区 -> 二次确认分区 -> 点击加号,选择大小和格式 -> 点击应用开始分区
  2. 新的分区在 /Volimes 目录下
  3. 因为 android-7.1.1_r6 22.12G, 编译完成占用 67.4G, 因此选择 80G
  4. 判断当前shell : echo $0 -> -bash

移动硬盘分区

  1. 购入移动硬盘,抹掉数据,改成 ExFat 格式
  2. 使用命令行进行 250G 分区
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 250g ~/android.dmg
  1. 双击新加 android.img.sparseimage ,将其挂载

Repo 下载源码

  1. repo: 方便 checkout Android 源码这种众多 git 项目汇聚的大项目
  2. 命令
//下载repo
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo //初始化 repo,使用清华镜像
$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-9.0.0_r3 // 下载源码,开启4个并发
$ repo sync -j4
  1. 也可替换成国内镜像,比如清华、中科
  2. 下载时间长,使用国内镜像还是蛮快的,应该是4,5个小时吧
  3. repo 下载报超时。repo 是对 git 的封装,给 git 设置代理
  4. 可以修改 mac 节能设置,防止休眠。系统设置 -> 节能 -> 勾选“防止进入睡眠”

编译

  1. 设置文件描述符限制
$ ulimit -S -n 1024
  1. 编译个系统浏览器 apk
// 清除缓存
make clobber
// 初始化环境
source build/envsetup.sh
// 打包浏览器
mmm packages/apps/Browser2/ // or 自动生成依赖
mmma packages/apps/Browser2/
  1. 编译源码
//根目录下执行,环境设置命令
source build/envsetup.sh
// 选择编译的源码类型
lunch
// 可以选择1. aosp_arm-eng 或2. aosp_arm64-eng
1
//查看本机CPU 核数, machdep.cpu.thread_count
sysctl machdep.cpu
//编译,使用核数的两倍, 这个耗时也就,差不多6个小时
make -j16
//启动虚拟机
emulator

源码导入 Android Studio 查看

  1. 编译 idegen
source build/envsetup.sh // 将执行文件设置为临时变量
mmm development/tools/idegen/ //生成idegen.jar文件 // 结果:
[100% 5/5] Install: out/host/darwin-x86/framework/idegen.jar #### build completed successfully (07:31 (mm:ss)) ####
  1. 执行脚本 idegen.sh
development/tools/idegen/idegen.sh

//结果
Read excludes: 83ms
Traversed tree: 1886971ms
  1. 编译完成,在AOSP 根目录下可以看到生成的 android.ipr 和 android.iml 文件
- android.ipr : 保存工程相关的设置
- android.iml : 用来描述 modules
  1. 导入。Android Studio -> File -> Open 选择 android.ipr 文件
  2. 精简导入
// 项目 全部项目导入,一两个小时还完成不了,因此精简下
// 修改 android.iml 的excludeFolder, 只保留 frameworks 和 package 包
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<excludeFolder url="file://$MODULE_DIR$/art"/>
<excludeFolder url="file://$MODULE_DIR$/bionic"/>
<excludeFolder url="file://$MODULE_DIR$/bootable"/>
<excludeFolder url="file://$MODULE_DIR$/build"/>
<excludeFolder url="file://$MODULE_DIR$/compatibility"/>
<excludeFolder url="file://$MODULE_DIR$/cts"/>
<excludeFolder url="file://$MODULE_DIR$/dalvik"/>
<excludeFolder url="file://$MODULE_DIR$/developers"/>
<excludeFolder url="file://$MODULE_DIR$/development"/>
<excludeFolder url="file://$MODULE_DIR$/device"/>
<excludeFolder url="file://$MODULE_DIR$/external"/>
<excludeFolder url="file://$MODULE_DIR$/hardware"/>
<excludeFolder url="file://$MODULE_DIR$/kernel"/>
<excludeFolder url="file://$MODULE_DIR$/libcore"/>
<excludeFolder url="file://$MODULE_DIR$/libnativehelper"/>
<excludeFolder url="file://$MODULE_DIR$/ndk"/>
<excludeFolder url="file://$MODULE_DIR$/out"/>
<excludeFolder url="file://$MODULE_DIR$/pdk"/>
<excludeFolder url="file://$MODULE_DIR$/platform_testing"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilts"/>
<excludeFolder url="file://$MODULE_DIR$/projectFilesBackup"/>
<excludeFolder url="file://$MODULE_DIR$/sdk"/>
<excludeFolder url="file://$MODULE_DIR$/system"/>
<excludeFolder url="file://$MODULE_DIR$/test"/>
<excludeFolder url="file://$MODULE_DIR$/toolchain"/>
<excludeFolder url="file://$MODULE_DIR$/tools"/>

碰到的问题

Could not find a supported mac sdk

问题:

本机 mac 10.14.3, 执行编译报 "Could not find a supported mac sdk: [“10.10” “10.11” “10.12” “10.13”] "

网上的解决之道:

x86_darwin_host.go 文件新增 "10.14"系统,让其支持

找到
build/soong/cc/config/x86_darwin_host.go
修改
darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.13",
"10.14",

后遗症:

这么改完后,不报这个问题了,但是问题转移了,成为下面那个问题了。

Undefined symbols for architecture i386

本机 mac 10.14, 其实是不支持 i386 架构,强行修改不行,搜索千百度,终于在 Google 论坛的 Android Building 组里面看到一些有用信息

I have solved this issue.You can download MacOSX10.13.sdk on https://github.com/phracker/MacOSX-SDKs/releases and copy it to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs

简述之:

  1. https://github.com/phracker/MacOSX-SDKs/releases 下载 MacOsx 10.13 sdk
  2. 将该sdk 拷贝到 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs, 我这里的 Xcode.app 是 Xcode-beta
  3. x86_darwin_host.go 文件新增 "10.14"系统去掉,让他使用 10.13 编译

结语

整个工程耗时耗力,也算是自己的一场磨难。

致谢

  1. macOS(Sierra 10.12)上Android源码(AOSP)的下载、编译与导入到Android Studio (最详细)
  2. Android源码:2、下载详解(二)(支持移动硬盘、mac)—亲测成功 (移动硬盘分区)
  3. 自己动手编译Android源码(超详细) (模块编译)
  4. 搭建编译环境 (android 官方文档)
  5. Getting the following error while building aosp using mmm command. (解决困扰我许久的 i386 问题)

Android 源码编译之旅的更多相关文章

  1. 有关android源码编译的几个问题

    项目用到编译环境,与源码有些差异不能照搬,关键是连源码都没编译过,下面基本上是行网上照的各种自学成才的分享,病急乱投医了,都记在下面作为参照吧. 1.验证是否编译正确,在终端执行 emulator & ...

  2. Android源码编译jar包BUILD_JAVA_LIBRARY 与BUILD_STATIC_JAVA_LIBRARY的区别(二)

    上文简单介绍了BUILD_JAVA_LIBRARY 与BUILD_STATIC_JAVA_LIBRARY编译出来jar包的区别, 那么你如果拿到了一个内容是dex格式的jar包,而你又偏偏需要这个ja ...

  3. 【Android开发】构建Android源码编译环境

    原文:http://android.eoe.cn/topic/android_sdk 构建Android源码编译环境 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  4. [Android Pro] Android源码编译之Nexus5真机编译

    reference to : http://blog.csdn.net/liu1075538266/article/details/51272398 1.   前言 在Android安全的研究工作中, ...

  5. Android源码编译make的错误处理

    android源码下载:官方下载 或参考android源码下载方式 Android编译版本: PLATFORM_VERSION=4.0.1(最新Android 4.0.1) OS 操作系统平台: Li ...

  6. 加速android源码编译

    添加缓存环境变量 : 在 ~/.bashrc 环境变量文件中 添加 export USE_CCACHE=1环境变量, 加速随后的编译过程; 分配缓存磁盘大小 为 ccache 指定磁盘中的一部分大小, ...

  7. Android源码编译出错解决办法

    编译环境:Ubuntu12.04 64位 Android源码:Android 4.3 以下问题是笔者亲自碰到,通过网上查询整合在一起的. 1.error while loading shared li ...

  8. android源码编译1

    一.环境说明: 1.liunx系统:Ubuntu12.04 2.jdk:sun-java6-jdk 3.g++4.5 gcc4.5 二.android源码的目录结构 |-- Makefile |-- ...

  9. android 源码编译中的错误 解决

    1.编译种错误提示: arm-none-linux-gnueabi-gcc: directory: No such file or directory arm-none-linux-gnueabi-g ...

随机推荐

  1. 机器学习基石笔记:03 Types of Learning

    原文地址:https://www.jianshu.com/p/86b2a9cef742 一.学习的分类 根据输出空间\(Y\):分类(二分类.多分类).回归.结构化(监督学习+输出空间有结构): 根据 ...

  2. 【app】自动化环境搭建(Appium)for java

    Appium来做app自动化相信大家都很熟悉了吧,就不再赘述他的概念和作用了,我们接下来着重介绍怎么来搭建整个app自动化环境,整个环境包括如下几个步骤: 1.安装jdk和eclipse及配置jdk的 ...

  3. 项目总结一:情感分类项目(emojify)

    一.Emojifier-V1 模型 1. 模型 (1)前向传播过程: (2)损失函数:计算the cross-entropy cost (3)反向传播过程:计算dW,db dz = a - Y_oh[ ...

  4. sql server 索引阐述系列二 索引存储结构

    一.概述. "流光容易把人抛,红了樱桃,绿了芭蕉“ 转眼又年中了,感叹生命的有限,知识的无限.在后续讨论索引之前,先来了解下索引和表数据的内部结构,这一节将介绍页的存储,页分配单元类型,区的 ...

  5. w7 python35 输出中文乱码解决

    1.乱码纷争在python自带的控制台正常 但是cmd就跪了,用的vs code也是同样问题,不想以前学习python27那么单纯,前面加个#UTF就可以了 网上寻求解决办法 import io,sy ...

  6. ZOJ Problem Set - 3706

    #include <cstdio> #include <cstdlib> #include <cstring> #include <set> #incl ...

  7. Spring mybatis源码篇章-MapperScannerConfigurer关联dao接口

    前言:Spring针对Mybatis的XML方式的加载MappedStatement,通过引入MapperScannerConfigurer扫描类来关联相应的dao接口以供Service层调用.承接前 ...

  8. python三大神器之pip

    pip是一款管理python各类包和库的工具,非常好用.下文介绍常用的一些命令. ● 安装:pip install 库名 也可以指定版本:pip install 库名=版本 ● 卸载:pip unin ...

  9. 飞跃式发展的后现代 Python 世界

    飞跃式发展的后现代Python世界 如果现代Python有一个标志性特性,那么简单说来便是Python对自身定义的越来越模糊.在过去的几年的许多项目都极大拓展了Python,并重建了“Python”本 ...

  10. Angular2入门:TypeScript的接口