1、下载Android源码
由于我的系统~目录下没有.bash_profile文件,所以要手动创建一个。
mac OSX bash_profile文件
A typical install of OS X won't create a .bash_profile for you. When you want to run functions from your command line, this is a must-have.
Start up Terminal
Type "cd ~/" to go to your home folder
Type "touch .bash_profile" to create your new file.
Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit.
Type ". .bash_profile" to reload .bash_profile and update any functions you add.
export PS1="/[/033[36m/]/u/[/033[m/]@/[/033[32m/]/h:/[/033[33;1m/]/w/[/033[m/]/$ "export CLICOLOR=1export LSCOLORS=ExFxBxDxCxegedabagacadalias ls='ls -GFh'export CFLAGS=-Qunused-argumentsexport CPPFLAGS=-Qunused-arguments
http://redfinsolutions.com/blog/creating-bashprofile-your-mac
于是最后下载Android源码前的最后一步就是,修改文件标识符限制:
由于Mac OS 默认将同时打开的文件标识符数量限制得太小,并行编译处理时可能会超出这个限制。所以在 ~/.bash_profile 里加上这么一段:
# set the number of open files to be 1024
ulimit -S -n 1024
2、转帖
Section 2: Android源码下载与编译
这部分在http://source.android.com/source/downloading.html中有详细说明每步作用
1. 准备源码下载工具repo
建立一个文件夹用于放工具repo,并将其路径写入.bash_profile环境变量
<code style="line-height: 14px;"><span class="pln" style="color: rgb(0, 0, 0);">$ mkdir </span><span class="pun" style="color: rgb(102, 102, 0);">~</span><span class="str" style="color: rgb(0, 136, 0);">/bin $ PATH=~/</span><span class="pln" style="color: rgb(0, 0, 0);">bin</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln" style="color: rgb(0, 0, 0);">$PATH</span></code>
<span class="pln" style="color: rgb(0, 0, 0);">$ <span class="pln" style="font-family: Roboto, sans-serif;">curl http</span><span class="pun" style="font-family: Roboto, sans-serif; color: rgb(102, 102, 0);">:</span><span class="com" style="font-family: Roboto, sans-serif; color: rgb(136, 0, 0);">//commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo</span> </span><span class="com" style="color: rgb(136, 0, 0);"></span><span class="pln" style="color: rgb(0, 0, 0);"> $ chmod a</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="pln" style="color: rgb(0, 0, 0);">x </span><span class="pun" style="color: rgb(102, 102, 0);">~</span><span class="str" style="color: rgb(0, 136, 0);">/bin/</span><span class="pln" style="color: rgb(0, 0, 0);">repo</span>
3. 建立源码文件夹并下载源码目录manifest
建立工作目录
<span class="pln" style="color: rgb(0, 0, 0);">$ mkdir Source $ cd Source</span>
建立工作目录在工作目录中下载源码目录文件manifest
<span class="pln" style="color: rgb(0, 0, 0);">$ repo init </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">u https</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="com" style="color: rgb(136, 0, 0);">//android.googlesource.com/platform/manifest</span>开始同步代码:
<span style="color: rgb(136, 0, 0);">$ repo sync</span>在这个同步代码过程中,可能会有很多次断线或停滞,关闭终端重新repo sync即可, 在所有同步完成前,此目录都会为空,看不到任何文件,只有用ls -a可以看到一个.git文件夹
4.建立好环境变量并开始编译
<code style="line-height: 14px;"><span class="pln" style="color: rgb(0, 0, 0);">$ source build</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="pln" style="color: rgb(0, 0, 0);">envsetup</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln" style="color: rgb(0, 0, 0);">sh</span></code>用源码中的文件设置好编译的环境变量
<code style="line-height: 14px;"><span class="pln" style="color: rgb(0, 0, 0);">$ lunch full</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">eng</span></code>选择好要编译的版本为模拟器版本,具体各版本选项可用lunch命令进行选择
<code style="line-height: 14px;"><span class="pln" style="color: rgb(0, 0, 0);">$ make <span style="font-family: Arial; font-size: 14px; line-height: 26px;">goldfish_armv7_defconfig </span></span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln" style="color: rgb(0, 0, 0);">j4</span></code>然后使用make命令开始编译,j4为代码编译时所采用的线程数, armv7_defconfig代表将arm V7的.config文件作为kernel的配置文件