2、編譯前的準(zhǔn)備工作,配置JDK1.5環(huán)境(使用最新的JDK1.6反倒是編譯不過(guò)去) 在Android中使用谷歌自己開(kāi)發(fā)的Java虛擬機(jī)內(nèi)核技術(shù)(JVM),稱(chēng)為Dalvik,該Java虛擬機(jī)在Android手機(jī)上執(zhí)行Java程序.谷歌表示,即使在手機(jī)的限制性硬件上,Dalvik也能使Java程序運(yùn)行得很快.與我們通常使用的Java虛擬機(jī)的一個(gè)顯著的區(qū)別就是,Android并不屬于Sun公司在1999年成立的Java標(biāo)準(zhǔn)制定組織(Java Community Process, 簡(jiǎn)稱(chēng)JCP)的一部分.JCP負(fù)責(zé)處理和審批各種Java技術(shù)和技術(shù)規(guī)范,將新的Java特點(diǎn)系統(tǒng)化為應(yīng)用程序編程接口(API).
在android/dalvik/libcore/dom/src/test/java/org/w3c/domts下有很多java源文件,這意味著編譯Android之前需要先安裝JDK。
下載jdk 1.5的地址 http://java.sun.com/products/archive/j2se/5.0_06/index.html
如果使用jdk1.6的版本將會(huì)出現(xiàn)如下的提示。
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version of java.
Your version is: java version "1.6.0_17".
The correct version is: 1.5.
Please follow the machine setup instructions at
將下載的jdk-1_5_0_06-linux-i586.bin復(fù)制到/usr/local/添加執(zhí)行權(quán)限并執(zhí)行安裝
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->chmod +x jdk-1_5_0_06-linux-i586.bin
./jdk-1_5_0_06-linux-i586.bin
安裝后出現(xiàn)jdk1.5.0_06文件夾,編輯/etc/profile文件添加JAVA_HOME變量和其他的編譯變量
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->JAVA_HOME=/usr/local/jdk1.5.0_06
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export ANDROID_JAVA_HOME=$JAVA_HOME
執(zhí)行source /etc/profile獲取新的環(huán)境變量信息,執(zhí)行java -version查看當(dāng)前的JDK版本。
3、編譯前的準(zhǔn)備工作, 準(zhǔn)備Ubuntu 9.10必要的編譯環(huán)境
準(zhǔn)備Ubuntu9.10中的編譯環(huán)境第一就是GCC的環(huán)境,需要安裝build-essential這個(gè)軟件包,同時(shí)要添加zlib1g-dev flexbison gperf libsdl-dev libesd0-dev libncurses5-dev libx11-dev等編譯需要的軟件包。
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->apt-get -y install build-essential zlib1g-dev flex bison gperf libsdl-dev libesd0-dev libncurses5-dev libx11-dev
4、執(zhí)行make命令開(kāi)始編譯
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->root@ubuntu:~# make
target thumb C: libwnndict <= packages/inputmethods/OpenWnn/libs/libwnnDictionary/engine/ndldic.c
target thumb C: libwnndict <= packages/inputmethods/OpenWnn/libs/libwnnDictionary/engine/ndrdic.c
target thumb C: libwnndict <= packages/inputmethods/OpenWnn/libs/libwnnDictionary/engine/necode.c
target thumb C: libwnndict <= packages/inputmethods/OpenWnn/libs/libwnnDictionary/engine/ndcommon.c
target thumb C: libwnndict <= packages/inputmethods/OpenWnn/libs/libwnnDictionary/engine/nj_str.c
target SharedLib: libwnndict (out/target/product/generic/obj/SHARED_LIBRARIES/libwnndict_intermediates/LINKED/libwnndict.so)
target Non-prelinked: libwnndict (out/target/product/generic/symbols/system/lib/libwnndict.so)
target Strip: libwnndict (out/target/product/generic/obj/lib/libwnndict.so)
Generated: (out/target/product/generic/android-info.txt)
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_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
出現(xiàn)上面的提示信息說(shuō)明編譯已經(jīng)完成,同時(shí)會(huì)發(fā)現(xiàn)在代碼目錄下多了一個(gè)out目錄。
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->lvs@ubuntu:~$ ls
bianyi andorind.odt Desktop hardware prebuilt 模板 音樂(lè)
bionic development Makefile repo 視頻 桌面
bootable examples.desktop myandroid system 圖片
build external out vendor 文檔
dalvik frameworks packages 公共的 下載
5、安裝Android模擬器android-sdk-linux_x86
到google網(wǎng)站下載http://developer.android.com/sdk/index.html頁(yè)面下載android-sdk_r04-linux_x86.tgz到/usr/local/并解壓,加壓后文件夾/usr/local/android-sdk-linux_86/tools/中包含有 emulator模擬器。
編輯/etc/profile添加模擬器執(zhí)行環(huán)境變量
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--># Android emulator
PATH=”$PATH:/home/lvs/out/host/linux-x86/bin”
ANDROID_PRODUCT_OUT=/home/lvs/out/target/product/generic
export ANDROID_PRODUCT_OUT
啟動(dòng)模擬器
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->root@ubuntu:~/out/target/product/generic#/usr/local/android-sdk-linux_86/tools/emulator -image system.img -datauserdata.img -ramdisk ramdisk.img
點(diǎn)擊查看大圖
點(diǎn)擊查看大圖