编译android源码

首先搭建android编译环境。

      (一)安装配置java5

      1 先安装java6(编译android需要java5,此处为推荐)

         打开终端,执行以下命令,或使用Adept/新立得软件管理器,在其中分别搜索"sun-java6-jre"和"sun-java6-jdk"并标记安装。 

         sudo apt-get install sun-java6-jre
         如果空间富裕,建议安装一个JDK。

         sudo apt-get install sun-java6-jdk
         提示:安装过程中需要你回答是否同意使用协议(终端中红蓝色的提示界面),此时按tab键至OK,再按回车即可正常安装。

      2 安装java5

        

      如果是ubuntu910版本,安装java5时需要更新源,方法:

         将下面更新放到更新源最前面
          更新的源:sudo gedit /etc/apt/sources.list
      deb http://cn.archive.ubuntu.com/ubuntu/ jaunty multiverse
      deb http://cn.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse

 

      sudo apt-get install sun-java5-jre

       sudo apt-get install sun-java5-jdk 

      3 设置当前默认的java解释器和编译器: (ubuntu9.10如果没有安装多个java虚拟机的话可以跳过这一步。)

         sudo update-alternatives --config java
         执行后会出现类似如下的画面:

There are 2 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
+        1    /usr/lib/jvm/java-6-openjdk/jre/bin/java
          2    /usr/lib/jvm/java-6-sun/jre/bin/java
*         3    /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
Press enter to keep the default[*], or type selection number:

输入 有包含 "sun" 的行的前面的数字。如上面显示,则输入3,然后回车确定。(编译android需要配置java5

sudo update-alternatives --config javac

操作和前面类似。

       4 配置JAVA环境变量:

     sudo gedit /etc/environment

        在其中添加如下两行:

     JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
     ANDROID_JAVA_HOME=$JAVA_HOME
     CLASSPATH=.:/usr/lib/jvm/java-1.5.0-sun/lib

        要使配置生效必须重启机器或者在命令行输入

     . /etc/environment

       5 配置JVM的优先级: (ubuntu9.10如果没有安装多个java虚拟机的话可以跳过这一步。)

     sudo gedit /etc/jvm

        将文件中的

     /usr/lib/jvm/java-1.5.0-sun

        这一行填入到配置块的顶部

 

 (二)安装交叉编译器及其他编译工具

 

1.1.1       FLEX

Flex is a tool for generating scanners.

# sudo apt-get install flex

1.1.2       BISON

Bison is a general-purpose parser generator.

       # sudo apt-get install bison

 

1.1.3       gperf

gperf is a program that generates perfect hash functions.

       # sudo apt-get install gperf

 

1.1.4       libsdl-dev

SDL is a library that allows programs portable low level access to a video framebuffer, audio output, mouse, and keyboard.

       # sudo apt-get install libsdl-dev

1.1.5       libesd0-devl

This program is designed to mix together several digitized audio streams for playback by a single device.

       # sudo apt-get install libesd0-dev

 

1.1.6       libwxgtk2.6-dev

This package provides files needed to compile wxWidgets programs.

# sudo apt-get install libwxgtk2.6-dev

 

1.1.7       zlib1g-dev

zlib is a library implementing the deflate compression method.

       # sudo apt-get install zlib1g-dev

 

1.1.8       build-essential

This package contains an informational list of packages which are considered essential for building Debian packages.

       # sudo apt-get install build-essential

 

1.1.9       libncurses5-dev

This package contains the header files, static libraries and symbolic links.

       # sudo apt-get install libncurses5-dev

1.1.10 Uboot-mkimage

This package contains the mkimage utility.

       # sudo apt-get install uboot-mkimage

 

1.2             Cross Tool

1. Copy the cross tool package to /usr/local/arm

   If the arm directory is not exist in host pc then create the directory

       # mkdir /usr/local/arm

       # cp 4.3.1-eabi-armv6-20080707.tar.bz2 /usr/local/arm

      

2. unzip the code using tar command

       # tar xvjf 4.3.1-eabi-armv6-20080707.tar.bz2

 

3. Add source path in your environment file

# vi ~/.bashrc

Add the source path

PATH=$PATH:/usr/local/arm/4.3.1-eabi-armv6/usr/bin

# source ~/.bashrc

 

4 unzip the code using tar command

# tar xvjf cross-4.2.2-eabi.tar.bz2 -C /usr/local/arm

 

 

1.3             Build Android

1. 用tar命令将源码解压到某路径下path/.     

2. Move to android directory and build it.

       # cd path/android(这个是你解压android源码后的路径)

       # make(这步是编译,可能会需要很长时间)

-------------------------------------------------------------------------------------------------------------

明天再写如何在Eclipse下调试android源码

 

posted @ 2010-03-18 20:16  Lynn_doo  阅读(2287)  评论(0编辑  收藏  举报