Android源码同步及分支切换

简单说一下,第一次下载安卓源码,网上百度了很多教程,照着做没问题,就是很费流量,大概用了150G左右的流量。

但是对于我来说,由于同步源码的时候,没有注意分支的指定,所有同步了最新的master版本,为了切换回想要的Android5.1版本着实下了一跳,很怕再150G,都是钱啊。下面简单介绍下同步过程及遇到的问题的解决办法。

https://blog.csdn.net/song19891121/article/details/50099857

我是跟着上述连接中的大神做的。

其中有几个问题:

1、文中提到的

//轮到curl工具了,我们使用curl工具下载repo,

并将其放置到bin目录curl https://storage-googleapis.lug.ustc.edu.cn/git-repo-downloads/repo > ~/bin/repo

这个curl工具下载地址如果不好用,可以换用如下地址重新下载:

curl "https://php.webtutor.pl/en/wp-content/uploads/2011/09/repo" > ~/bin/repo

注:引号是要有的。

2、执行repo init 时,一定要指定安卓版本,不然就会默认同步最新的master版本,很大,很费时间和流量。

repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b Android版本

3、执行repo sync命令开始同步代码时,出现报错:

fatal:../platform/art.git"does not appear to be a git repository.

解决办法:首先,cd ~/android/.repo目录下,vim打开manifest.xml文件,

  修改文件中“fetch= "..."”这一行为:

fetch= “git://Android.git.linaro.org/”

保存并退出。

回到cd ~/android 目录下,重新执行 repo sync

4、执行repo sync过程中,可能会出现timeout的报错,这是网络问题,重新执行repo sync就行。

  但是repo的断点续传能力只有10分钟,所以为了更快更省流量的同步安卓源码,建议写一个shell脚本,每次repo sync中断,自动重新执行。

脚本的写法可以自行百度。


安卓源码切换分支

查看可切换的分支
cd .repo/manifests

git branch -a | cut -d / -f 3 

然后cd ~/android 目录下执行

repo init -b android-5.1.1_r1
repo sync (not needed if your local copy is up to date)
repo start android-5.1.1_r1 --all 

完成后,查看当前的分支
repo branches

中间依然出现了问题:

如果本地版本库中的源代码有一些改动,执行repo sync命令后,会出现如下提示(笔者本地为例):

build/: discarding 1 commits
dalvik/: discarding 2 commits
kernel/: discarding 6 commits
packages/apps/Calendar/: discarding 1 commits
packages/apps/Contacts/: discarding 2 commits
packages/apps/Mms/: discarding 1 commits
packages/apps/Music/: discarding 1 commits
packages/apps/Phone/: discarding 1 commits
vendor/embinux/support-tools/: discarding 1 commits 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这时需要使用下面的操作命令:

1,repo forall -c git reset --hard
2,repo forall -c git checkout android-5.1.1_r1
3,repo sync
  • 1
  • 2
  • 3

最后再执行

repo start android-5.1.1_r1 --all 

这样,本地代码就和服务端仓库中的代码完全一致了。


  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值