zoukankan      html  css  js  c++  java
  • Downloading Android Source Code

    Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的分布式版本控制软件,它不同于Subversion、CVS这样的集中式版本控制系统。在集中式版本控制系统中只有一个仓 库(repository),许多个工作目录(working copy),而像Git这样的分布式版本控制系统中(其他主要的分布式版本控制系统还有 BitKeeper  Mercurial  GNU Arch  Bazaar Darcs  SVK  Monotone 等),每一个工作目录都包含一个完整仓库,它们可以支持离线工作,本地提交可以稍后提交到服务器上。分布式系统理论上也比集中式的单服务器系统更健壮,单服务器系统一旦服务器出现问题整个系统就不能运行了,分布式系统通常不会因为一两个节点而受到影响 。
    因为Android是由kernel、Dalvik、Bionic、prebuilt、build等多个Git项目组成,所以Android项目编写了一个名为Repo的Python的脚本来统一管理这些项目的仓库,使得Git的使用更加简单。

    From the detail of android Git repositories,see https://android.googlesource.com/

    A.

    1.Install GIT.

      Download and install GIT for your development system. GIT 1.7.11.2 for Windows.

    2.Install Repo.

      Google Official Doc:http://source.android.com/source/downloading.html

      Download and setup the repo tool, as described on the Android open source project site.

      Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Version Control.]

      Note: Developers using Windows must use a Linux compatibility package, such as cygwin, to install and run repo. Within your compatibility environment, you must install curlgit and python to be able to download and use the repo tool.

      To install:first ensure the bin folder in your current user's root directory(Create it if none.If you don't know where to create bin folder,you can try cd ~/bin and check the hint.my is c/User/aa/bin),then add (~/bin) to the PATH environment variables,download Repo by curl and save it to ~/bin/repo.

      curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo

    You can also download it manually,and put it in the  appointed folder.Just need to open the address in browser 
       https://dl-ssl.google.com/dl/googlesource/git-repo/repo.
    If the link if out of date,go to google official site to update it.(http://source.android.com/source/downloading.html)
    Ensure it has executable access:
      chmod a+x ~/bin/repo

      

     3.Initialize Repository.

     If you want the lastest main source code,you need repo.Create a directory first,for example,~/android,enter and repo init.

      repo init -u git://android.git.kernel.org/platform/manifest.git 

     If you want a branch instead of main,you need -b to specify the branch name:

      repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake 

        repo init -u http://android.git.kernel.org/platform/manifest.git -b cupcake 

     Use git branch to list all the branch.

     However,an error occurs when I use it:

      

     It need the python interpreter.Now I run it in Git Bash.I switch to Cygwin Terminal and add a new environment variable C:\Users\aa\bin.Then it works well.

      

      unable to connect to android.git.kernel.org may also occurs.It is because there are too many servers which provider downloads at port:80.You need to replace the git with http:

      

     It may takes a long time,depends on you internet.You will see  repo initialized in /android at last.

      

     About the email and name ,you can set it by:

    git config --global user.email "[email=xxxxx@xxxxxxx]xxxxx@xxxxxxx[/email]"
    git config --global user.name "xxxxxx"

    4.Synchronization(download)

     Modify file .repo/manifests/default.xml,replace the fetch="git://android.git.kernel.org/"  with fetch="http://android.git.kernel.org/".(I skip this step.)

     repo sync

     repo sync project1 project2 …

     如果是同步Android中的单个项目,只要在项目目录下执行简单的 git pull  即可。

    B.

    If you just need the code of some project,like kernel/common. Use Git directly。

      git clone git://android.git.kernel.org/kernel/common.git 
    In the consideration of the whole download of Linux Kernel,it may take a long time also.

    如果需要某个branch的代码,用git checkout即可。比如我们刚刚拿了kernel/common.get的代码,那就先进入到common目录,然后用下面的命令:
      git checkout origin/android-goldfish-2.6.27 -b goldfish 
    这样我们就在本地建立了一个名为goldfish的android-goldfish-2.6.27分支,代码则已经与android-goldgish-2.6.27同步。我们可以通过git branch来列出本地的所有分支。

    C.

    通过GitWeb下载代码 

    另外,如果只是需要主线上某个项目的代码,也可以通过 GitWeb 下载,在shortlog利用关键字来搜索特定的版本,或者找几个比较新的tag来下载还是很容易的。
    Git最初是为Linux内核开发而设计,所以对其他平台的支持并不好,尤其是Windows平台,必须要有Cygwin才可以。现在,得益于 msysgit 项目,我们已经可以不需要Cygwin而使用Git了。另外, Git Extensions 是一个非常好用的Windows Shell扩展,它能与资源管理器紧密集成,甚至提供了Visual Studio插件。它的官方网站上有一分不错的 说明文档 ,感兴趣的朋友可以看一看。
    至于Git的参考文档,我推荐 Git Magic ,这里还有一个 Git Magic的中文版 
    获取Anroid Linux Kernel过程:
    [root@localhost ~]# mkdir bin
    [root@localhost ~]# curl http://android.git.kernel.org/repo >~/bin/repo
    [root@localhost bin]# cd bin/
    [root@localhost bin]# chmod a+x ~/bin/repo
    [root@localhost bin]# cd /usr/local/src/
    [root@localhost src]# mkdir project-android
    [root@localhost src]# cd project-android/
    [root@localhost project-android]# git clone git://android.git.kernel.org/kernel/common.git
    这里会下载半天,下载完成之后:
    [root@localhost src]# cd common
    [root@localhost common]# ls
    arch     CREDITS        drivers   include Kbuild MAINTAINERS net             samples   sound
    block    crypto         firmware init     kernel Makefile     README          scripts   usr
    COPYING Documentation fs        ipc      lib     mm           REPORTING-BUGS security virt
     
    [root@localhost common]# git branch -a
    * android-2.6.27
    diff
    remotes/origin/HEAD ->
     origin/android-2.6.27 
    remotes/origin/android-2.6.25
    remotes/origin/android-2.6.27
    remotes/origin/android-2.6.29
    remotes/origin/android-goldfish-2.6.27
    remotes/origin/android-goldfish-2.6.29
     

    D.

    通过第三方repo下载代码 

    在获取 Android 源码的第一步,就是需要获得 Git 和 Repo,在获得 “repo” 的时候,就需要到 “kernel.org” 获取:

    curl http://android.git.kernel.org/repo >~/bin/repo

    基于种种原因,你是无法同步的,会提示:

    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
    curl: (7) couldn't connect to host

    即使你之前已经获取了 “repo”,而你在同步 Android 源码时候也会提示:

    android.git.kernel.org[0: 130.239.17.13]: errno=Connection refused
    android.git.kernel.org[0: 199.6.1.173]: errno=Connection refused
    android.git.kernel.org[0: 2001:6b0:e:4017:1972:112:1:0]: errno=Network is unreachable
    android.git.kernel.org[0: 2001:500:60:10:1972:112:1:0]: errno=Network is unreachable
    fatal: unable to connect a socket (Network is unreachable)
    error: Cannot fetch platform/bionic

    故本文这里就使用另外源,来取得 Android 源码。

    一、获取 repo

      这个是老外自己建立的,使用这个源可以获得 repo,但是后续的源码也是使用老外自己建立的。首先获取 repo:

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

      给 “repo” 增加相应权限:chmod a+x ~/bin/repo

      添加环境变量:PATH=~/bin:$PATH

      这样就获取了第三方的 repo。

    二、同步 Android 源码

      同样是使用老外自己的源,首先进入工作目录:cd ~/android/system/

      repo init -u git://codeaurora.org/platform/manifest.git可以查看所有分支

      同步源码:repo init -u git://codeaurora.org/platform/manifest.git -b gingerbread

        查看分支时注意只有[New Branch]的才可以下载,[New Tag]的无法下载。

      开始同步:repo sync

      这个是第三方的源码,不知道其中会不会有什么问题,我自己也同步了。请大家自己斟酌,这里仅仅是提供一种方法。

     For Detail:http://source.android.com/source/downloading.html

  • 相关阅读:
    C#中Bitmap类实现对图像操作的一些方法
    C# GDI+ 文字操作
    C#中使用GDI+实现复杂打印
    【Python基础】json.dumps()和json.loads()、json.dump()和json.load()的区分
    【Python爬虫】selenium基础用法
    【Python爬虫】PyQuery解析库
    【Python爬虫】BeautifulSoup 解析库
    【Python爬虫】正则表达式与re模块
    【Python爬虫】Requests库的基本使用
    【Python基础】*args,**args的详细用法
  • 原文地址:https://www.cnblogs.com/qiengo/p/2598764.html
Copyright © 2011-2022 走看看