Android内核开发:理解和掌握repo工具(含被墙后的下载方法)

本文详细介绍Repo工具的原理及使用方法,包括安装步骤、下载源码流程、manifest.xml文件结构解析以及常用命令汇总。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


由于Android源码是用repo工具来管理的,因此,搞Android内核开发,首先要搞清楚repo是什么东西,它该怎么使用?作为《Android内核开发》系列文章的第二篇,我们首先谈谈对repo工具的理解和使用。


1. repo是什么?

repo是一种代码版本管理工具,它是由一系列的Python脚本组成,封装了一系列的Git命令,用来统一管理多个Git仓库。


2. 为什么要用repo?

因为Android源码引用了很多开源项目,每一个子项目都是一个Git仓库,每个Git仓库都有很多分支版本,为了方便统一管理各个子项目的Git仓库,需要一个上层工具批量进行处理,因此repo诞生。

repo也会建立一个Git仓库,用来记录当前Android版本下各个子项目的Git仓库分别处于哪一个分支,这个仓库通常叫做:manifest仓库。


3. 怎么安装repo?

官方的repo脚本下载方法:

curl http://commondatastorage.googleapis.com/git-repo-downloads/repo >  ./repo


由于官网被墙,目前可以使用的repo脚本下载方法如下(两者选一):

$ git clone git://git.omapzoom.org/git-repo.git
$ git clone git://aosp.tuna.tsinghua.edu.cn/android/git-repo.git/  

$ cp git-repo/repo  ./repo


或者修改手头已有的被墙的repo文件:

REPO_URL = ‘git://git.omapzoom.org/git-repo.git‘
REPO_URL = ‘git://aosp.tuna.tsinghua.edu.cn/android/git-repo‘ 

REPO_REV = ‘stable‘


当然,你也可以去我的GitHub下载这个repo文件,地址:

https://github.com/Jhuster/AOSP/blob/master/repo


4. 怎么下载源码?

上面说过,Android源码分支其实由一个叫manifest仓库来管理起来的,因此,下载源码首先要clone这个manifest仓库。这个仓库里面有一个XML文件,其实就是一个文件清单,列出了本代码仓库依赖哪些代码,该去哪下载,分支是什么。


一般用repo init命令来clone这个manifest仓库,例如,如果要下载Android源码,则方法如下:

$ repo init -u https://android.googlesource.com/platform/manifest


当然,上面的官网被墙了,因此,推荐如下镜像(两者选一):

$ repo init -u git://git.omapzoom.org/platform/manifest.git
$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest

初始化完毕后,你会在本地的.repo文件夹中看到manifest仓库的内容,这个文件夹中最重要的文件是manifest.xml(有的仓库用的是default.xml,然后指向具体的xml),它就是上面说到的文件清单。

如果要选择特定版本的Android源码,或者在已下载的源码基础上切换到其他版本,则可以使用-b选项:

$ repo init -u git://git.omapzoom.org/platform/manifest.git -b android-5.0.2_r1 
$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest -b android-5.0.2_r1


然后使用 repo sync 命令进行同步即可下载好全部的Android源码了。


5. manifest.xml文件清单的组成

上面提到了repo init需要初始化一个manifest仓库,仓库中含有一个很重要的manifest.xml文件清单,其实这个manifest.xml并不复杂的,它就是用XML文件的格式记录了本项目依赖的各个Git仓库的名称、地址,以及分支等信息。常用的元素如下所示:


(1) manifest 最顶层的XML元素

(2) remote  设置远程git服务器的属性,如名称、根URL地址等

(3) project 需要clone的Git仓库,path表示本机路径,name表示远程版本库的相对路径

(4) copyfile 执行拷贝操作,把URL/$src地址的文件拷贝到./$dest

其实,如果不使用repo工具,也是可以对照manifest.xml文件清单直接使用“git clone”的方式一个project一个project的下载的,然后对每个project进行git checkout特定的分支。


7. 常用repo命令

这一块网上文章很多,我就不详细讲解了,只列出常用命令。

(1) repo init   // 初始化repo仓库

(2) repo sync   // 下载源码

(3) repo start  // 创建分支

(4) repo checkout //切换分支

(5) repo branches //查看分支

(6) repo status   //查看文件状态


8. 小结

关于repo工具就介绍到这里了,有任何疑问欢迎留言或者来信lujun.hust@gmail.com交流,也欢迎关注我的新浪微博 @卢_俊 获取最新的文章和资讯。

本文出自 “对影成三人” 博客,请务必保留此出处http://ticktick.blog.51cto.com/823160/1653304

由于Android源码是用repo工具来管理的,因此,搞Android内核开发,首先要搞清楚repo是什么东西,它该怎么使用?作为《Android内核开发》系列文章的第二篇,我们首先谈谈对repo工具的理解和使用。


1. repo是什么?


repo是一种代码版本管理工具,它是由一系列的Python脚本组成,封装了一系列的Git命令,用来统一管理多个Git仓库。


2. 为什么要用repo?


因为Android源码引用了很多开源项目,每一个子项目都是一个Git仓库,每个Git仓库都有很多分支版本,为了方便统一管理各个子项目的Git仓库,需要一个上层工具批量进行处理,因此repo诞生。


repo也会建立一个Git仓库,用来记录当前Android版本下各个子项目的Git仓库分别处于哪一个分支,这个仓库通常叫做:manifest仓库。


3. 怎么安装repo?


官方的repo脚本下载方法:


curl http://commondatastorage.googleapis.com/git-repo-downloads/repo >  ./repo


由于官网被墙,目前可以使用的repo脚本下载方法如下(两者选一):


$ git clone git://git.omapzoom.org/git-repo.git
$ git clone git://aosp.tuna.tsinghua.edu.cn/android/git-repo.git/  

$ cp git-repo/repo  ./repo


或者修改手头已有的被墙的repo文件:


REPO_URL = ‘git://git.omapzoom.org/git-repo.git‘
REPO_URL = ‘git://aosp.tuna.tsinghua.edu.cn/android/git-repo‘ 

REPO_REV = ‘stable‘


当然,你也可以去我的GitHub下载这个repo文件,地址:


https://github.com/Jhuster/AOSP/blob/master/repo


4. 怎么下载源码?


上面说过,Android源码分支其实由一个叫manifest仓库来管理起来的,因此,下载源码首先要clone这个manifest仓库。这个仓库里面有一个XML文件,其实就是一个文件清单,列出了本代码仓库依赖哪些代码,该去哪下载,分支是什么。


一般用repo init命令来clone这个manifest仓库,例如,如果要下载Android源码,则方法如下:


$ repo init -u https://android.googlesource.com/platform/manifest


当然,上面的官网被墙了,因此,推荐如下镜像(两者选一):


$ repo init -u git://git.omapzoom.org/platform/manifest.git
$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest


初始化完毕后,你会在本地的.repo文件夹中看到manifest仓库的内容,这个文件夹中最重要的文件是manifest.xml(有的仓库用的是default.xml,然后指向具体的xml),它就是上面说到的文件清单。


如果要选择特定版本的Android源码,或者在已下载的源码基础上切换到其他版本,则可以使用-b选项:


$ repo init -u git://git.omapzoom.org/platform/manifest.git -b android-5.0.2_r1 
$ repo init -u git://aosp.tuna.tsinghua.edu.cn/android/platform/manifest -b android-5.0.2_r1


然后使用 repo sync 命令进行同步即可下载好全部的Android源码了。


5. manifest.xml文件清单的组成


上面提到了repo init需要初始化一个manifest仓库,仓库中含有一个很重要的manifest.xml文件清单,其实这个manifest.xml并不复杂的,它就是用XML文件的格式记录了本项目依赖的各个Git仓库的名称、地址,以及分支等信息。常用的元素如下所示:


(1) manifest 最顶层的XML元素


(2) remote  设置远程git服务器的属性,如名称、根URL地址等


(3) project 需要clone的Git仓库,path表示本机路径,name表示远程版本库的相对路径


(4) copyfile 执行拷贝操作,把URL/$src地址的文件拷贝到./$dest


其实,如果不使用repo工具,也是可以对照manifest.xml文件清单直接使用“git clone”的方式一个project一个project的下载的,然后对每个project进行git checkout特定的分支。


7. 常用repo命令


这一块网上文章很多,我就不详细讲解了,只列出常用命令。


(1) repo init   // 初始化repo仓库


(2) repo sync   // 下载源码


(3) repo start  // 创建分支


(4) repo checkout //切换分支


(5) repo branches //查看分支


(6) repo status   //查看文件状态


8. 小结


关于repo工具就介绍到这里了,有任何疑问欢迎留言或者来信lujun.hust@gmail.com交流,也欢迎关注我的新浪微博 @卢_俊 获取最新的文章和资讯。


本文出自 “对影成三人” 博客,请务必保留此出处http://ticktick.blog.51cto.com/823160/1653304

To make edits to changes after they have been uploaded, you should use a tool like git rebase -i or git commit --amend to update your local commits. After your edits are complete: Make sure the updated branch is the currently checked out branch. For each commit in the series, enter the Gerrit change ID inside the brackets: # Replacing from branch foo [ 3021 ] 35f2596c Refactor part of GetUploadableBranches to lookup one specific... [ 2829 ] ec18b4ba Update proto client to support patch set replacments # Insert change numbers in the brackets to add a new patch set. # To create a new change record, leave the brackets empty. After the upload is complete the changes will have an additional Patch Set. If you only want to upload the currently checked out Git branch, you can use the flag --current-branch (or --cbr for short). diff repo diff [<PROJECT_LIST>] Shows outstanding changes between commit and working tree using git diff. download repo download <TARGET> <CHANGE> Downloads the specified change from the review system and makes it available in your project's local working directory. For example, to download change 23823 into your platform/build directory: repo download platform/build 23823 A repo sync should effectively remove any commits retrieved via repo download. Or, you can check out the remote branch; e.g., git checkout m/master. Note: There is a slight mirroring lag between when a change is visible on the web in Gerrit and when repo download will be able to find it for all users, because of replication delays to all servers worldwide. forall repo forall [<PROJECT_LIST>] -c <COMMAND> Executes the given shell command in each project. The following additional environment variables are made available by repo forall: REPO_PROJECT is set to the unique name of the project. REPO_PATH is the path relative to the root of the client. REPO_REMOTE is the name of the remote system from the manifest. REPO_LREV is the name of the revision from the manifest, translated to a local tracking branch. Used if you need to pass the manifest revision to a locally executed git command. REPO_RREV is the name of the revision from the manifest, exactly as written in the manifest. Options: -c: command and arguments to execute. The command is evaluated through /bin/sh and any arguments after it are passed through as shell positional parameters. -p: show project headers before output of the specified command. This is achieved by binding pipes to the command's stdin, stdout, and sterr streams, and piping all output into a continuous stream that is displayed in a single pager session. -v: show messages the command writes to stderr. prune repo prune [<PROJECT_LIST>] Prunes (deletes) topics that are already merged. start repo start <BRANCH_NAME> [<PROJECT_LIST>] Begins a new branch for development, starting from the revision specified in the manifest. The <BRANCH_NAME> argument should provide a short description of the change you are trying to make to the projects.If you don't know, consider using the name default. The <PROJECT_LIST> specifies which projects will participate in this topic branch. Note: "." is a useful shorthand for the project in the current working directory. status repo status [<PROJECT_LIST>] Compares the working tree to the staging area (index) and the most recent commit on this branch (HEAD) in each project specified. Displays a summary line for each file where there is a difference between these three states. To see the status for only the current branch, run repo status. The status information will be listed by project. For each file in the project, a two-letter code is used: In the first column, an uppercase letter indicates how the staging area differs from the last committed state. letter meaning description - no change same in HEAD and index A added not in HEAD, in index M modified in HEAD, modified in index D deleted in HEAD, not in index R renamed not in HEAD, path changed in index C copied not in HEAD, copied from another in index T mode changed same content in HEAD and index, mode changed U unmerged conflict between HEAD and index; resolution required In the second column, a lowercase letter indicates how the working directory differs from the index. letter meaning description - new/unknown not in index, in work tree m modified in index, in work tree, modified d deleted in index, not in work tree Was this page helpful? Let us know how we did:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值