repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r2
repo sync
这种方法经过我的测试是成功的,有可能提示 找不到 android-5.0.0_r2,多重复几次 应该可以成功,因为在 https://android.googlesource.com/platform/manifest/+refs
中可以找到branch: android-5.0.0_r2
同步代码中有可能出现的问题
1.branch没有找到
可以先到 https://android.googlesource.com/platform/manifest/+refs中查看 你所同步的branch 是否存在,这个里面的内容是变化的,google有可能会添加/删除branch,比如 之前存在的branch:lollipop-release,已经不存在了。
2.无法访问gerrit.googlesource.com
user:~/work/android-5.0$ repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r2
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable
解决方案: 由于大家都知道的原因,我们经常无法访问google站点,与我们init 代码相关的站点有两个 android.googlesource.com 和 gerrit.googlesource.com,在/etc/hosts 中添加如下两行
74.125.21.98 android.googlesource.com
74.125.21.98 gerrit.googlesource.com
如果上面的ip地址不起作用(将ip地址输入到浏览器地址栏),那么就去网上查找google网站最新的hosts
经过我的测试 添加 这两行后 repo init 成功,让后通过 repo sync 同步代码