Mac下的JDK环境见文章:Mac下的Java安装及卸载
首先,安装Repo
确认你有bin目录
$ mkdir ~/bin
$ PATH=~/bin:$PATH
安装Repo工具
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo $ chmod a+x ~/bin/repo如果你没有curl,麻烦装一下吧,我用brew安装的。安装命令:sudo brew install curl
你可能遇到这样的问题:
curl: (56) Recv failure: Connection reset by peer
最新给的目录可能有问题,那就试试老的:
curl http://git-repo.googlecode.com/files/repo-1.12 > ~/bin/repo
到此 Repo安装完毕。
初始化Repo客户端
1.创建源码的文件夹,Mac注意大小写。因为Mac下大小写是敏感的。
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
2.运行Repo init
repo init -u https://android.googlesource.com/platform/manifest
这时候,你发现 repo: command not found
没关系,请执行下面的两个命令:
echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
export PATH=$PATH:~/bin
然后重新执行
repo init-u https://android.googlesource.com/platform/manifest
然后我得到这么一个提示:
A new repo command ( 1.18) is available.
... You should upgrade soon:
cp /Users/hector/WORKING_DIRECTORY/.repo/repo/repo /Users/hector/bin/repo
执行之
得到下面的信息:
Traceback (most recent call last):
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/main.py", line 408, in <module>
_Main(sys.argv[1:])
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/main.py", line 388, in _Main
result = repo._Run(argv) or 0
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/main.py", line 138, in _Run
result = cmd.Execute(copts, cargs)
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/subcmds/init.py", line 327, in Execute
self._ConfigureUser()
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/subcmds/init.py", line 245, in _ConfigureUser
name = self._Prompt('Your Name', mp.UserName)
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/project.py", line 574, in UserName
self._LoadUserIdentity()
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/project.py", line 587, in _LoadUserIdentity
u = self.bare_git.var('GIT_COMMITTER_IDENT')
File "/Users/hector/WORKING_DIRECTORY/.repo/repo/project.py", line 2005, in runner
p.stderr))
error.GitError: manifests var:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'yourname@yourname.(none)')
提示让设置git的账号,设置之
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
要和下面的账号一致。
1. 浏览器登录https://android.googlesource.com/new-password,并用gmail帐号(就是你初始化repo时填写的gmail邮箱)登录;
2. 点击网页上的“允许访问”,
进入后copy “Staying Authenticated”下边灰色部分的内容:
1 machine android.googlesource.com login git...............
2 machine android-review.googlesource.com login git...................
3.将copy的内容写进~/.netrc文件中,如果你的/home下没有这个文件的话,可以创建一个
4. repo init -u https://android.googlesource.com/a/platform/manifest (注意该URL中多了一个/a)
得到如下信息:
Your identity is: yourname <yourmail@gmail.com>
If you want to change this, please re-run 'repo init' with --config-name
Testing colorized output (for 'repo diff', 'repo status'):
black red green yellow blue magenta cyan white
bold dim ul reverse
Enable color display in this user account (y/N)? y
repo initialized in /Users/yourname/WORKING_DIRECTORY
上面提示信息,也说了,如果你的名字和邮箱不对怎么办,重新运行
'repo init' with --config-name
去设置喽,这里暂且不表。
5. repo sync
现在就可以下载Android源码。
下载源码到此结束,我的Mac开始下载源码了。我要睡觉了。
补:用了好几天下载源码的血泪教训告诉大家,记得一定要弄个hosts文件。要不然就老是断断续续的,参考http://opengg.me/613/generate-hosts-for-google/