Android 在ubuntu上下載和編譯系統原始碼
網上也有很多這樣的教程,這裡只是把它記錄下來,方便日後檢視。
下載原始碼
分為以下幾個步驟:
1、配置安裝下載環境
配置 JDK環境
安裝curl、git-core軟體
sudo apt-get install curl
sudo apt-get install git-core
2、建立一個~/bin目錄,並新增到環境變數中
mkdir ~/binPATH=~/bin:$PATH
3、下載repo指令碼並修改許可權為可執行
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo (這個有可能會下載超時)
curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo"> ~/bin/repo (上面下載失敗可以下載這個)
chmod a+x~/bin/repo
4、建立一個儲存android原始碼的目錄,修改為最大許可權,並進入到該目錄下
mkdir /opt/android_source
sudo chmod –R 777 /opt/android_source
cd /opt/android_source
5、初始化repo,並選擇要下載的分支(版本)
repo init -u https://android.googlesource.com/platform/manifest (這個是最新原始碼)
repo init -u https://android.googlesource.com/platform/manifest -b android-4.2_r1 (這個是Android4.2系統原始碼,其它版本只要更換分支號就可以)
6、提示輸入你的姓名、郵箱。
7、開始下載原始碼
repo sync
常遇到的錯誤情況:
情況1:
error:Failed onnect o android.googlesource.com:443;
Connection efused while accessing
https://android.googlesource.com/a/platform/frameworks/base/info/refs
fatal: HTTP request failed
error: Cannot fetch platform/tools/motodev
error: Cannot fetch platform/frameworks/base
error: Cannot fetch platform/prebuilts/sdk
error: Exited sync due to fetch errors
解決:
編輯/etc/hosts檔案
vim /etc/hosts
增加下面內容,儲存
74.125.31.82 www.googlesource.com
74.125.31.82 android.googlesource.com
203.208.46.172 cache.pack.google.com
59.24.3.173 cache.pack.google.com
編譯原始碼
1、 下載所需軟體
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
2、建立連結sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so
3、配置gcc
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
4、編譯原始碼
cd /opt/android_source
source build/envsetup.sh 或 .build/envsetup.sh
lunch full-eng
make -j4
5、啟動模擬器emulator