在Ubuntu上下載、編譯和安裝Android最新源碼

來源:互聯網
上載者:User

標籤:android   des   style   http   java   color   

        看完了前面說的幾本書之後,對Linux Kernel和Android有一定的認識了,是不是心裡蠢蠢欲動,想小試牛刀自己編譯一把Android源碼了呢?一直習慣使用Windows系統,而Android源碼是不支援在Windows上編譯上,於是決定使用虛擬機器安裝Ubuntu,然後下載、編譯和安裝Android源碼。

     一. 環境準備。

     1. 磁碟空間預留20G左右,記憶體3G,由於一邊要跑主機,一邊要跑虛擬機器,記憶體要求還是比較高的,這樣才會比較流暢。

     2. 安裝VMWare 7.1.4。我的作業系統是Win7,VMWare的版本號碼要新一點的,舊版本號碼的VMWare在網路支援上比較差,由於要在虛擬機器上下載Android源碼,沒有網路是萬萬不行的。

     3. 安裝好VMWare後,接下來就安裝Ubuntu系統了。我選擇眼下最新的版本號碼ubuntu-11.04-alternate-i386,從網上查到的資料說,要編譯Android源碼,Ubuntu的最低版本號碼是8.04。下載好後,安裝時採用一直預設安裝就可以。

     4. 安裝Git工具。Android源碼採用Git工具來管理,與SVN相比,這是一種分布式的源碼管理工具,而SVN是集中式的源碼管理工具。要安裝Git工具,在Ubuntu上運行下面命令就可以:

     [email protected]:~$ sudo apt-get install git-core gnupg

     5. 安裝Java SDK。在Ubuntu上運行下面命令:

     [email protected]:~$  sudo add-apt-repository ppa:ferramroberto/java      [email protected]:~$  sudo apt-get update      [email protected]:~$  sudo apt-get install sun-java6-jre sun-java6-plugin      [email protected]:~$  sudo apt-get install sun-java6-jdk                 6. 依賴的其他包。在Ubuntu上運行下面命令:
      [email protected]:~$ sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
     7. 調試工具。在Ubuntu上運行下面命令:
      [email protected]:~$ sudo apt-get install valgrind
    二. 下載Android源碼project。
     1. 下載repo工具。在Ubuntu上運行下面命令:
     [email protected]:~$ wget https://dl-ssl.google.com/dl/googlesource/git-repo/repo     [email protected]:~$ chmod 777 repo     [email protected]:~$ cp repo /bin/     2. 下載Android最新版本號碼源碼。在Ubuntu上運行下面命令:

     [email protected]:~$ mkdir Android

     [email protected]:~$ cd Android      [email protected]:~/Android$ repo init -u https://dl-ssl.google.com/dl/googlesource/git-repo/repo      [email protected]:~/Android$ repo sync      經過漫長的等待(我下載了兩三天)後,就能夠把Android源碼下載下來了。其間可能還有經曆下載中斷的情況,這時僅僅要又一次運行repo sync就能夠了。     三. 編譯Android源碼。     1. 編譯。在Android檔案夾下運行下面命令:     [email protected]:~/Android$ make      第一次編譯要等待比較久的時間,編譯成功後,能夠看到下面的輸出:      Target system fs image:    out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img      Install system fs image: out/target/product/generic/system.img      Target ram disk: out/target/product/generic/ramdisk.img      Target userdata fs image: out/target/product/generic/userdata.img      Installed file list: out/target/product/generic/installed-files.txt       2. 編譯過程中可能會遇到的問題。     問題一:You are attempting to build on a 32-bit system.     兩個地方須要個改動:     1)改動build/core檔案夾下的main.mk檔案:     ifeq ($(BUILD_OS),linux)      build_arch := $(shell uname -m)      #Change the following line for building on a 32-bit system.      #ifneq (64,$(findstring 64,$(build_arch)))      ifneq (i686,$(findstring i686,$(build_arch)))      $(warning ************************************************************)      $(warning You are attempting to build on a 32-bit system.)      $(warning Only 64-bit build environments are supported beyond froyo/2.2.)     2)找到下列檔案:     /external/clearsilver/cgi/Android.mk     /external/clearsilver/cs/Android.mk     /external/clearsilver/java-jni/Android.mk     /external/clearsilver/util/Android.mk     改動LOCAL_CFLAGS和LOCAL_LDFLAGS變數:     # This forces a 64-bit build for Java6      # Change the following two lines for building on a 32-bit system.      # LOCAL_CFLAGS += -m64      # LOCAL_LDFLAGS += -m64      LOCAL_CFLAGS += -m32      LOCAL_LDFLAGS += -m32     問題二:Undefined reference to `__dso_handle‘      external/stlport/src/monetary.cpp:39: undefined reference to `__dso_handle‘out/target/product/vm/obj/SHARED_LIBRARIES/libstlport_intermediates/src/locale.o: In function `__static_initialization_and_destruction_0‘:     external/stlport/src/locale.cpp:29: undefined reference to `__dso_handle‘out/target/product/vm/obj/SHARED_LIBRARIES/libstlport_intermediates/src/locale_impl.o: In function `__static_initialization_and_destruction_0‘:     external/stlport/src/locale_impl.cpp:31: undefined reference to `__dso_handle‘out/target/product/vm/obj/SHARED_LIBRARIES/libstlport_intermediates/src/locale_impl.o: In function `std::_Locale_impl::make_classic_locale()‘:     external/stlport/src/locale_impl.cpp:670: undefined reference to `__dso_handle‘     external/stlport/src/locale_impl.cpp:667: undefined reference to `__dso_handle‘out/target/product/vm/obj/SHARED_LIBRARIES/libstlport_intermediates/src/locale_impl.o:external/stlport/src/locale_impl.cpp:604: more undefined     references to `__dso_handle‘ follow     collect2: ld returned 1 exit status      改動external/stlport/dll_main.cpp,添?下面聲明:     extern "C" {             void * __dso_handle = 0;      }       四. 編譯SDK,這一步是可選的。      1. 編譯。運行下面命令:      [email protected]:~/Android$ make sdk      2. 編譯過程中可能會遇到的問題。     問題一:找不到bios.bin和vgabios-cirrus.bin檔案     couldn‘t locate source file: usr/share/pc-bios/bios.bin     couldn‘t locate source file: usr/share/pc-bios/vgabios-cirrus.bin     注意,這裡的usr/share檔案夾指的是~/Android/out/host/linux-x86檔案夾下的usr/share檔案夾,改動辦法是複製~/Android/prebuilt/common下的pc-bios檔案夾到~/Android/out/host/linux-x86/usr/share就可以:      [email protected]:~/Android$ cp ~/Android/prebuilt/common/pc-bios ~/Android/out/host/linux-x86/usr/share     問題二:找不到ddmlib-tests.jar、 ninepath-tests.jar 、common-tests.jar 和sdkuilib-tests.jar檔案    在~/Android/out/host/linux-x86/framework這個檔案夾下,能夠找到下面幾個檔案common.jar、ddmlib.jar、ninepatch.jar、sdkuilib.jar這四個檔案,然後將它們分別複製一份,並重新命名,命名的原則非常easy,就是在原有的名字後面跟上-tests就可以。    五. 安裝編譯好的Android鏡像到模擬器上。    1. 環境變數設定:     [email protected]:~/Android$ export PATH=$PATH:~/Android/out/host/linux-x86/bin       [email protected]:~/Android$ export ANDROID_PRODUCT_OUT=~/Android/out/target/product/generic     當中,~/Android/out/host/linux-x86/bin有我們要啟動並執行emulator命令,而~/Android/out/target/product/generic是Android鏡像存放檔案夾,下面運行emulator命令時會用到。    2. 運行模擬器。     [email protected]:~/Android$ emulator     模擬器運行須要四個檔案,各自是Linux Kernel鏡像zImage和Android鏡像檔案system.img、userdata.img和ramdisk.img。運行emulator命令時,假設不帶不論什麼參數,則Linux Kernel鏡像預設使用~/Android/prebuilt/android-arm/kernel檔案夾下的kernel-qemu檔案,而Android鏡像檔案則預設使用ANDROID_PRODUCT_OUT檔案夾下的system.img、userdata.img和ramdisk.img,也就是我們剛剛編譯出來的鏡像問題。    當然,我們也能夠以指定的鏡像檔案來運行模擬器,即運行emulator時,即:     [email protected]:~/Android$ emulator -kernel ./prebuilt/android-arm/kernel/kernel-qemu -sysdir ./out/target/product/generic -system system.img -data userdata.img -ramdisk ramdisk.img     到這裡,我們就能夠在模擬器上運行我們自己編譯的Android鏡像檔案了,是不是非常酷呢?可是注意,這裡說的Android鏡像檔案,僅僅是包含system.img、userdata.img和ramdisk.img這三個檔案,而Linux Kernel鏡像用的是Android為我們先行編譯好的kernel-qemu鏡像。那麼,有沒有辦法使用我們自己編譯的Linux Kernel鏡像呢?答案上肯定的,這樣我們就能夠全然DIY自己的Android系統了!我將在下一篇文章描寫敘述假設編譯自己的Linux Kernel鏡像,敬請期待~ 


PS:主線上最新源碼是不穩定版本號碼,使用過程可能會有問題

另外,假設從官方下載不到源碼(大家懂的),能夠從這裡下:http://zhu.im/Android/

更正式的源碼編譯方法,請參考官網:http://source.android.com/source/initializing.html

老羅的新浪微博:http://weibo.com/shengyangluo,歡迎關注!

聯繫我們

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