Android 在ubuntu上下載和編譯系統源碼

來源:互聯網
上載者:User

標籤:android   style   http   color   os   檔案   io   for   

網上也有很多這樣的教程,這裡只是把它記錄下來,方便日後查看。

官網教程:http://source.android.com/source/building.html


下載源碼

分為以下幾個步驟:

1、配置安裝下載環境

  配置 JDK環境

  安裝curl、git-core軟體

 sudo apt-get install curl
 sudo apt-get install git-core

2、建立一個~/bin目錄,並添加到環境變數中

 mkdir ~/bin
 PATH=~/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


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.