ubuntu 11.04下Android源碼的擷取

來源:互聯網
上載者:User

這兩天著手編譯源碼的準備工作,在此記錄下過程,方便自己備份的同時也希望能對後來者有所協助。

Attention:本文環境是在ubuntu 11.04下擷取並編譯android 2.3.3的源碼,過程參考了easwy的博文http://easwy.com/blog/archives/compile-android-gingerbread-2-3-1/ 以及google官網 http://source.android.com/source/downloading.html 。

官網上的要求資訊為:

In general you will need:

  • Python 2.4 -- 2.7, which you can download from python.org.

  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from java.sun.com.

  • Git 1.5.4 or newer. You can find it at git-scm.com.

  • (optional) Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc. Download from valgrind.org.

另外補充:需要6GB以上磁碟空間,依賴的deb包:flex、bison、gperf、libsdl-dev、libesd0-dev、libwxgtk2.6-dev、build-essential、zip、curl

一、下載前準備工作

首先,準備好所需磁碟空間後,就來安裝開發過程中需要的一些開發包,在終端中執行以下命令:

 $ sudo apt-get install git-core gnupg flex bison gperf libsdl1.2-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev 

在此處,需要注意兩點:1.libsdl版本為1.2;2.zlib1g-dev別看錯了是1而不是l,當然非手敲的tx就不存在這個問題了。

然後需要安裝java環境,在這裡我嘗試了兩種方法。

方法一(線上):

執行

sudo apt-get install sun-java6-jdk

提示:

E: Package 'sun-java6-jdk' has no installation candidate

ubuntu後續版本提供的軟體源變化了,按照官網說明,解決方案如下:

$sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"

 

第二條命令執行時會出現提示:

Error: 'deb-src http://archive.canonical.com/ lucid partner' invalid

直接無視之,繼續執行:

sudo apt-get update
sudo apt-get install sun-java6-jdk

安裝開始。

方法二(離線):

參考網址 http://jayghost.iteye.com/blog/1245095

從官網下載jdk-6u29-linux-i586.bin

sudo chmod u+x jdk-6u29-linux-i586.bin

修 改bin檔案許可權,使其可執行。
然後執行

./jdk-6u29-linux-i586.bin

然後持續按斷行符號鍵,JDK解壓到檔案夾,得到jdk1.6.0_29.此時JDK安裝完畢。

下面進行配置環境變數。

/etc/profile 添加如下代碼:

JAVA_HOME=/usr/java/jdk1.6.0_29
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH  CLASSPATH

PS:jdk複製到/usr/java/下。

儲存重啟後 即可。

使用java -version來檢驗。

二、下載源碼

現在我們已經準備好了android源碼開發所需的環境(無錯誤),下載源碼的過程由於Android的源碼很是龐大,需要分Android源碼和核心兩部分擷取。核心部分的源碼我暫時是不用的,所以這裡只下載源碼。

1.先建立一個檔案夾存放Android目錄,並初始化repo:

wayne@ubuntu:~$ mkdir Android
wayne@ubuntu:~$ cd Android
wayne@ubuntu:~/Android$ mkdir bin
wayne@ubuntu:~/Android$ cd bin
wayne@ubuntu:~/Android/bin$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19731 100 19731 0 0 14034 0 0:00:01 0:00:01 --:--:-- 17157

在這裡,幾個月前http://android.git.kernel.org/已經無法訪問了,很多朋友如果用的是這個源下載網站,就會出現如下情況:

wayne@ubuntu:~/Android/bin$ curl http://android.git.kernel.org/repo >repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 244 100 244 0 0 75 0 0:00:03 0:00:03 --:--:-- 976

然後在之後的代碼初始化時就會出現如下錯誤:

./bin/repo: 行 1: 未預期的符號 `newline' 附近有語法錯誤
./bin/repo: 行 1: `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'

2.現在繼續。建立存放源碼目錄source,初始化所需的android源碼版本,在終端執行如下命令:

wayne@ubuntu:~/Android/bin$ sudo chmod a+x repo
wayne@ubuntu:~/Android/bin$ cd
wayne@ubuntu:~$ cd Android/source/
wayne@ubuntu:~/Android/source$ ../bin/repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.3_r1
gpg: 鑰匙環‘/home/wayne/.repoconfig/gnupg/secring.gpg’已建立
gpg: 鑰匙環‘/home/wayne/.repoconfig/gnupg/pubring.gpg’已建立
gpg: /home/wayne/.repoconfig/gnupg/trustdb.gpg:建立了信任度資料庫
gpg: 密鑰 920F5C65:公開金鑰“Repo Maintainer <repo@android.kernel.org>”已匯入
gpg: 合計被處理的數量:1
gpg: 已匯入:1

Get https://android.googlesource.com/tools/repo
remote: Counting objects: 1414, done
remote: Finding sources: 100% (78/78)
remote: Total 1414 (delta 917), reused 1414 (delta 917)
Receiving objects: 100% (1414/1414), 429.88 KiB | 169 KiB/s, done.
Resolving deltas: 100% (917/917), done.
From https://android.googlesource.com/tools/repo
* [new branch] maint -> origin/maint
* [new branch] master -> origin/master
* [new branch] stable -> origin/stable
...

這樣下來之後,會要求輸入使用者名稱和郵箱地址,隨意寫個就ok。

初始化完畢之後會出現:

repo initialized in /home/wayne/Android/source

現在完成初始化之後便可以下載了,在終端執行如下命令,開始下載:

wayne@ubuntu:~/Android/source$ ../bin/repo sync

下載全部的源碼需要很長時間,現在正在經曆漫長的等待……

過程中時常看一下,也許會出錯而中斷:

error: Exited sync due to fetch errors

遇到這些問題時,重新執行一遍../bin/repo sync就ok。

以上就是下載源碼全過程,歡迎交流指正。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.