使用本地AOSP镜像快速获取Android代码

来源:互联网 发布:下载搜狐新闻软件 编辑:程序博客网 时间:2024/04/29 19:20

说明

一次次的从AOSP mirror站点获取代码特别慢, 尤其是如果使用的还是google的AOSP Mirror而不是国内的. 因此如果在开发中需要经常性的切换Android branch/Tag, 对不同的Android版本进行开发验证与编译的话, 最好在本地建立一个次级的AOSP Mirror. 这样所有的Android版本都有了, 即节省了流量也节省了时间.


建立本地AOSP镜像

建立本地次级AOSP Mirror直接使用google提供的命令即可, 在repo init的命令后面加上--mirror即可, 例如下面是从TsingHua University的AOSP mirror获取本地一个Mirror.

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

然后再直接repo sync即可.

如果需要更新本地的Mirror,那么定期repo sync即可.

下面我们假设我们的本地mirror放在了:

/ExtDisk/android/aosp_mirror/


如何使用

假设我们根据某个build wiki知道我们要使用某个manifest.xml来repo init, 那么在执行完这条repo init之后, 就有一个.repo文件夹:

repo init -u https://github.com/bluez-android/aosp_platform_manifest.git -b kitkat
$ ls .repo/manifests  manifests.git  manifest.xml  repo

更改config文件

然后我们就需要更改fetch地址来使用我们的本地mirror了

打开.repo/manifests.git/config文件, 内容如下:

[core]repositoryformatversion = 0filemode = true[filter "lfs"]smudge = git-lfs smudge --skip -- %f[remote "origin"]url = https://github.com/bluez-android/aosp_platform_manifest.gitfetch = +refs/heads/*:refs/remotes/origin/*[branch "default"]remote = originmerge = refs/heads/kitkat

将里面的url地址更改为我们本地的mirror地址:

url = /ExtDisk/android/aosp_mirror/platform/manifest.git

更改manifest.xml文件

将.repo/manifest.xml前面的

           fetch="https://android.googlesource.com/" />


更改成下面的.., 即:

<?xml version="1.0" encoding="UTF-8"?><manifest>  <remote  name="aosp"           fetch=".." />

然后再进行repo sync即可. 例如:

repo sync --no-tags --no-clone-bundle


错误解决

如果没有正确更改,那么会出现找不到的提示:

Fetching project platform/external/valgrindFetching project platform/hardware/invensenseFetching project platform/system/securityFetching project platform/external/esdfatal: repository 'https://github.com/platform/external/esd/' not foundfatal: repository 'https://github.com/platform/hardware/invensense/' not foundfatal: repository 'https://github.com/platform/system/security/' not foundfatal: repository 'https://github.com/platform/external/valgrind/' not found
此时可以确定更改, 然后再重新repo sync即可.

如果正确的话, 那么就在log中有类似下面的输出:

$ repo sync --no-tags --no-clone-bundleFetching project platform/external/valgrindFetching project platform/hardware/invensenseFetching project platform/system/securityFetching project platform/external/esdremote: Counting objects: 25, done.remote: Compressing objects: 100% (22/22), done.remote: Total 25 (delta 0), reused 25 (delta 0)From /ExtDisk/android/aosp_mirror/platform/external/esd * [new branch]      donut-release -> aosp/donut-release

注意里面的From XXX

同时也可以在repo sync的过程中, 进入到.repo中的project目录下, 去查看是否从本地Mirror中获取:

$ cd .repo/projects/bootable/diskinstaller.git
$ git remote -vaosp/ExtDisk/android/aosp_mirror/platform/bootable/diskinstaller (fetch)aosp/ExtDisk/android/aosp_mirror/platform/bootable/diskinstaller (push)


如果没有对应的Tag,那么会提示:

fatal: Couldn't find remote ref refs/heads/kitkatfatal: The remote end hung up unexpectedlyfatal: Couldn't find remote ref refs/heads/kitkatfatal: The remote end hung up unexpectedly


本地AOSP镜像的分享

本地repo其实属于一个文件夹, 因此问题就成了如何共享这个问题夹. 自然我们可以像google一样在本地设立一个gitweb, 然后让其他同事或者开发者将code.google.com类似的地址换成我们的本地服务器的IP地址即可, 当然也可以不用这么麻烦, 如果仅仅是局域网内, 那么可以选择使用nfs来共享, 将权限设置为ReadOnly即可.

那么其他开发者在mount了这个nfs directory之后就可以像使用本地Mirrors一样了. 


参考

清华大学的AOSP Mirror帮助页面

0 0
原创粉丝点击