第一次用Mac下载Android源码,遇到过一些问题。下面总结下,记录遇到过得问题
一、配置mac相关环境,具体方法Google有给出
Setting up a Mac OS build environment
1、shell中输入如下命令,创建一个大小写敏感,40g大小的盘,名字后缀可能是.dmg或者.dmg.sparseimage,其中~/android.dmg可以更换位置。我的是生成的android.dmg.sparseimage
# hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/android.dmg
如下方式可以调整盘的大小
# hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage
在.bash_profile加上如下方法,方便挂载:
# mount the android file image
function mountAndroid { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }
# unmount the android file image
function umountAndroid() { hdiutil detach /Volumes/android; }
2、mac的jdk使用oracle的
jdk 8u45 or newer
3、安装需要的工具
安装xcode,可以使用如下命令(我没试过),也可以通过app store安装
$ xcode-select --install
在.bash_profile添加路径
export PATH=/opt/local/bin:$PATH
在Install MacPorts中下载macports,并安装;安装完之后需要执行下面的命令,才能使用macports
$ sudo port -d selfupdate
通过macports获取gmake,libsdl,git,gnupg
$ POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg
在.bash_profile中添加下面方法,修改文件描述符
# set the number of open files to be 1024
ulimit -S -n 1024
到这里,mac第一步环境搭建终于完成。
二、下载源码,具体方法Google已给出,但是由于国内导致源码下载失败,这个时候需要借助VPN才行
Downloading the Source
1、安装repo,把bin目录加入PATH
$ mkdir ~/bin
在.bash_profile中加入如下命令,和上面的结合一起
export PATH=/opt/local/bin:~/bin:$PATH
下载repo
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
2、进入到前面建好的盘android.dmg.sparseimage进行git配置
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
3、重点来了,下载Android源码
$ repo init -u https://android.googlesource.com/platform/manifest
国内原因,导致这个地址链接不上,就需要特殊方法获取源码
第一步要一个VPN账号,我使用的Green的VPN,在网络中添加一个VPN的网络
然后按照How to create a VPN connection via terminal?的方法配置shell中的vpn,就可以下载Android源码
具体方法在.bash_profile中添加如下方法,其中VPN(L2TP)2可以改成自己VPN的名字
function vpn-connect {
/usr/bin/env osascript <<-EOF
tell application "System Events"
tell current location of network preferences
set VPN to service "VPN(L2TP)2" -- your VPN name here
if exists VPN then connect VPN
repeat while (current configuration of VPN is not connected)
delay 1
end repeat
end tell
end tell
EOF
}
function vpn-disconnect {
/usr/bin/env osascript <<-EOF
tell application "System Events"
tell current location of network preferences
set VPN to service "VPN(L2TP)2" -- your VPN name here
if exists VPN then disconnect VPN
end tell
end tell
return
EOF
}
登录新的shell,首先输入vpn-connect,最后就是下载源码
$ vpn-connect
$ repo sync
祝大家下载Android源码顺利。