独辟蹊径系列 带着大家玩Android(2)

来源:百度文库 编辑:神马文学网 时间:2024/10/02 02:34:45
2、编译前的准备工作,配置JDK1.5环境(使用最新的JDK1.6反倒是编译不过去)

  在Android中使用谷歌自己开发的Java虚拟机内核技术(JVM),称为Dalvik,该Java虚拟机在Android手机上执行Java程序.谷歌表示,即使在手机的限制性硬件上,Dalvik也能使Java程序运行得很快.与我们通常使用的Java虚拟机的一个显着的区别就是,Android并不属于Sun公司在1999年成立的Java标准制定组织(Java Community Process, 简称JCP)的一部分.JCP负责处理和审批各种Java技术和技术规范,将新的Java特点系统化为应用程序编程接口(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的版本将会出现如下的提示。


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 http://source.android.com/download

  将下载的jdk-1_5_0_06-linux-i586.bin复制到/usr/local/添加执行权限并执行安装


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

  安装后出现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

  执行source /etc/profile获取新的环境变量信息,执行java -version查看当前的JDK版本。 

  3、编译前的准备工作, 准备Ubuntu 9.10必要的编译环境

  准备Ubuntu9.10中的编译环境第一就是GCC的环境,需要安装build-essential这个软件包,同时要添加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、执行make命令开始编译


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

   出现上面的提示信息说明编译已经完成,同时会发现在代码目录下多了一个out目录。


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->lvs@ubuntu:~$ ls
bianyi andorind.odt  Desktop           hardware   prebuilt  模板  音乐
bionic               development       Makefile   repo      视频  桌面
bootable             examples.desktop  myandroid  system    图片
build                external          out        vendor    文档
dalvik               frameworks        packages   公共的    下载

   5、安装Android模拟器android-sdk-linux_x86

  到google网站下载http://developer.android.com/sdk/index.html页面下载android-sdk_r04-linux_x86.tgz到/usr/local/并解压,加压后文件夹/usr/local/android-sdk-linux_86/tools/中包含有 emulator模拟器。

  编辑/etc/profile添加模拟器执行环境变量


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

   启动模拟器


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

点击查看大图

点击查看大图