cygwin环境下载android源码

· by author · Read in about 2 min · (257 words)

cygwin 环境准备

打开http://www.cygwin.com/ 下载set-x86_64.exe。安装时选择国内镜像 http://mirrors.163.com。

cygwin 安装时选择所有开发者选项。其它需要用到的工具有curl,vim,git 也需要全部选中安装。

curl ssl证书验证:

请求一个https 的api服务,看是否正常返回json数据

curl -i https://api.github.com/users/octocat/orgs

如果返回

curl: (77) error setting certificate verify locations:
  CAfile: C:\ruby\cacert.pem
  CApath: none

则执行以下命令

echo 'cacert=/etc/ssl/certs/ca-bundle.crt' > ~/.curlrc

再次请求api后,无错误提示,会正确返回json数据

HTTP/1.1 200 OK
Date: Tue, 15 Aug 2017 01:49:31 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 5
Server: GitHub.com
Status: 200 OK
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 1502764991
Cache-Control: public, max-age=60, s-maxage=60
Vary: Accept
ETag: "98f0c1b396a4e5d54f4d5fe561d54b44"
X-GitHub-Media-Type: github.v3; format=json
Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
Access-Control-Allow-Origin: *
Content-Security-Policy: default-src 'none'
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-XSS-Protection: 1; mode=block
X-Runtime-rack: 0.013540
Vary: Accept-Encoding
X-GitHub-Request-Id: C473:DA1A:1DE4A30:2E84DF1:59925328
[

]

android 源码下载配置

清华大学镜像安装教程 https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

不翻墙下载Android内核源码 http://blog.csdn.net/sunao2002002/article/details/53057374

建立当前用户的bin目录 mkdir ~/bin

建立源码存放的目录 在e盘下的的android目录

mkdir /cygdrive/e/android
cd /cygdrive/e/android

使用git clone下载 repo

git clone https://aosp.tuna.tsinghua.edu.cn/android/git-repo.git/

把git中的repo下载执行文件拷贝到用户的 bin目录中

cp git-repo/repo ~/bin/
chmod a+x ~/bin/repo

建立一个.repo目录,并且把git-repo重名为repo移动到该目录下

mkdir .repo
mv -r git-repo .repo/repo

打开bash

vim ~/.bashrc

在最后一行追加,repo 的镜像地址

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
export PATH=~/bin:$PATH

更新环境变量,使其立即生效

source ~/.bashrc

初始化仓库,查看各个版本号

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

初始化指定同步版本号

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.2_r8

开始同步源码树

repo sync

同步源码的时候会出现一个错误

error: unable to create file tests/P_str_escape/str\\escape.rs: No such file or directory
Traceback (most recent call last):
  File "/cygdrive/e/androidsrc/.repo/repo/main.py", line 531, in <module>
    _Main(sys.argv[1:])
  File "/cygdrive/e/androidsrc/.repo/repo/main.py", line 507, in _Main
    result = repo._Run(argv) or 0
  File "/cygdrive/e/androidsrc/.repo/repo/main.py", line 180, in _Run
    result = cmd.Execute(copts, cargs)
  File "/cygdrive/e/androidsrc/.repo/repo/subcmds/sync.py", line 821, in Execute
    project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
  File "/cygdrive/e/androidsrc/.repo/repo/project.py", line 1327, in Sync_LocalHalf
    self._InitWorkTree(force_sync=force_sync)
  File "/cygdrive/e/androidsrc/.repo/repo/project.py", line 2486, in _InitWorkTree
    raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree

解决方案:

打开e:\androidsrc\frameworks\compile\slang\tests\P_str_escape 目录,创建str 目录,并在str 目录中创建 escape.rs文件(文件内容为空)。

再次执行

repo --trace sync

自动动手编译Android源码及SDK http://blog.csdn.net/dd864140130/article/details/51718187 搭建编译环境 https://source.android.com/source/initializing?hl=zh-cn