Android源碼下載方法詳解

http://blog.csdn.net/pku_android/article/details/7082928

作者:張星 

相信很多下載過內核的人都對這個很熟悉
git clone git://android.git.kernel.org/kernel/common.git kernel
但是這是在以前,現在如果這麼執行的話,會顯示如下內容
Initialized empty Git repository in /home/star/working/kernel/.git/
android.git.kernel.org[0: 149.20.4.77]: errno=Connection refused
fatal: unable to connect a socket (Connection refused)
通過瀏覽器輸入http://android.git.kernel.org/,發現該網站已經被重定向爲http://source.android.com/source/downloading.html
可以在該頁面的最後發現內核的下載方法。

 

下面我們介紹一下Android源碼下載的步驟。

工作環境:

操作系統:Ubuntu 10.04   或  Ubuntu10.10

git程序 :1.7.0.4  或 1.7.1

轉載請註明出處:http://blog.csdn.net/pku_android

方法一:
1.1 初始化安裝環境
參考網頁http://source.android.com/source/initializing.html
主要要做的就是安裝jdk和安裝一些軟件包
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev \
  libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown \
  libxml2-utils
如果已經安裝了,就不許要這步了

1.2 無論下載內核和源碼,都需要進行如下操作
參考網頁http://source.android.com/source/downloading.html
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
建立一個文件夾,以便下載的內容保存其中
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

1.3 內核下載
$ git clone https://android.googlesource.com/kernel/common.git kernel
命令行最後面的kernel的意思是保存在這個文件夾下,所以可以是任何名字,該文件夾不需要自己去創建,最後的這個不寫也沒問題
如果想下載其他版本的內核
$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git clone https://android.googlesource.com/kernel/msm.git
$ git clone https://android.googlesource.com/kernel/omap.git
$ git clone https://android.googlesource.com/kernel/samsung.git
$ git clone https://android.googlesource.com/kernel/tegra.git
下載過程中,會有如下信息,速度快慢取決於網速了。
Initialized empty Git repository in /home/star/kernel/kernel/.git/
remote: Counting objects: 40, done
remote: Counting objects: 2073952, done
remote: Finding sources: 100% (208/208)
remote: Getting sizes: 100% (88/88)
remote: Compressing objects: 100% (2/2)
remote: Total 2073863 (delta 1735363), reused 2073862 (delta 1735363)
Receiving objects: 100% (2073863/2073863), 427.93 MiB | 318 KiB/s, done.
Resolving deltas: 100% (1735382/1735382), done.
在我下載的過程中,出現瞭如下問題
error: RPC failed; result=56, HTTP code = 2002 MiB | 23 KiB/s 
到現在我也不清楚是由於什麼原因導致的,猜測
1.1中所說的事情,都做了嗎?我發現有一些安裝包尚未安裝,安裝之。
或者,可能是網絡問題,重複執行一下,會發現並不是在同一個地方出現這個問題的,說不定哪次就成功了
或者,用別人的電腦下載一下(雖然方法是我發現的,可是並不是我第一個下載成功的,我遇到了RPC failed,後來讓同學嘗試,成功,之後我也嘗試了,在把所需要的安裝包都安裝後,也成功)

1.4 更換內核版本
由於在1.3中我寫的是kernel,這是可以看到當前目錄下出現了一個kernel文件夾
$ cd kernel/
$ ls
發現沒有任何內容
查看當前內核版本,master,不知道是什麼意思
$ git branch
* master
查看所有可用內核版本
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-2.6.39
  remotes/origin/android-3.0
  remotes/origin/master
可以看到目前只提供了少數的版本,只有2.6.39和3.0,比如我要下載2.6.39
$ git checkout -b android-2.6.39 origin/android-2.6.39
Switched to a new branch 'android-2.6.39'
該命令的android-2.6.39指的是分支的名字,其實是可以隨便取的,關鍵是origin/android-2.6.39,要對應git branch -a命令顯示的remotes後面的內容
完成後,查詢當前分支
$ git branch
* android-2.6.39
  master
$ ls
arch     Documentation  init     lib          README          sound
block    drivers        ipc      MAINTAINERS  REPORTING-BUGS  tools
COPYING  firmware       Kbuild   Makefile     samples         usr
CREDITS  fs             Kconfig  mm           scripts         virt
crypto   include        kernel   net          security
會看到突然出現很多文件夾,這就是內核了
由於誤操作
比如$ git checkout -b android-2.6.39 origin/android-2.6.39,只是輸入$ git checkout -b android-2.6.39,這時,會得到一個空的分支
$ git branch -a
* android-2.6.39
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-2.6.39
  remotes/origin/android-3.0
  remotes/origin/master
如果再次執行
$ git checkout -b android-2.6.39 origin/android-2.6.39
fatal: git checkout: branch android-2.6.39 already exists
一種方法,就是給把-b後面的android-2.6.39改爲其他名字,但是這個有問題的分支android-2.6.39還是會存在的
查看$ git branch --help,找到分支刪除的命令
$ git branch -D android-2.6.39
error: Cannot delete the branch 'android-2.6.39' which you are currently on.
需要切換分支,假設也存在android-3.0,當然也可以切換爲master或者其他存在的分支,$ git branch -a查看分支
$ git checkout android-3.0
Checking out files: 100% (37131/37131), done.
Switched to branch 'android-3.0'
$ git branch -D android-2.6.39
Deleted branch android-2.6.39 (was fe8bf45).

轉載請註明出處:http://blog.csdn.net/pku_android

方法二
2.1 參考1.1和1.2

2.2 類似於下載Android源碼的過程,先執行如下命令
$ repo init -u https://android.googlesource.com/platform/manifest
在這一步還需要用到gmail的郵箱
在下載Android源碼的過程中,並不會下載kernel,那怎樣才能既下載源碼,又下載kernel呢
參考網頁http://elinux.org/Android_Kernel_Download
 a kernel git tree並沒有被默認的Android manifest file引用
既然沒有引用,那就加上它
修改.repo/manifest.xml(目前的目錄爲1.2中已經建立的WORKING_DIRECTORY)
$ vim .repo/manifest.xml
加上這條語句
<project path="kernel/common" name="kernel/common" revision="android-2.6.39"/>
位置我覺得和其它的project選項並列即可。
版本號參考1.4,可能只能下載2.6.39和3.0

2.3 下載源碼和內核
$ repo sync
漫長的等待
如果我只想下載內核呢
很簡單,修改2.2提到的文件.repo/manifest.xml,把所有project標籤都刪除,再添加
<project path="kernel/common" name="kernel/common" revision="android-2.6.39"/>

 

轉載請註明出處:http://blog.csdn.net/pku_android


發佈了93 篇原創文章 · 獲贊 11 · 訪問量 90萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章