Andriod_ubuntu11.10配置开发编译环境

来源:互联网 发布:矩阵等价和矩阵相等 编辑:程序博客网 时间:2024/06/06 21:00

下载了ubuntu11.10,准备开发andriod,首先按照andriod官方的说明,进行配置编译开发环境

官方地址:http://source.android.com/source/initializing.html

Setting up a Linux build environment

These instructions apply to all branches, including master.

The Android build is routinely tested in house on recent versions ofUbuntu LTS (10.04), but most distributions should have the requiredbuild tools available. Reports of successes or failures on otherdistributions are welcome.

For Gingerbread (2.3.x) and newer versions, including the masterbranch, a 64-bit environment is required. Older versions can becompiled on 32-bit systems.

Note: It is also possible to build Android in a virtual machine.If you are running Linux in a virtual machine, you will need atleast 16GB of RAM/swap and 30GB or more of disk space in order tobuild the Android tree.

Detailed instructions for Ubuntu and MacOS follow. In general you will need:

  • Python 2.6 -- 2.7, which you can download from python.org.   这个我的ubuntu版本就是2.7.2

  • GNU Make 3.81 -- 3.82, which you can download from gnu.org,这个我的ubuntu版本就是3.8.1

  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both fromjava.sun.com.这个需要安装

  • Git 1.7 or newer. You can find it at git-scm.com.这个需要安装

Installing the JDK  它NND貌似自动apt-get没有安装包链接,不能安装,网上找了半天资料貌似要手动安装

参照下面的手动安装方法。


The Sun JDK is no longer in Ubuntu's main package repository. In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.

Java 6: for Gingerbread and newer

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"$ sudo apt-get update$ sudo apt-get install sun-java6-jdk

Java 5: for Froyo and older

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"$ sudo apt-get update$ sudo apt-get install sun-java5-jdk

Note: The lunch command in the build step will ensure that the Sun JDK isused instead of any previously installed JDK.


Ubuntu手动安装JDK

安装前可以查看一下jdk版本,进入终端 $java -version 回车,可以看到jdk版本是1. 4 .2的。

1. 手动安装jdk6

首先,在http://java.sun.com下载jdk-6u12-linux-i586.bin,据说这个操作起来比较简单,不需要转换。
然后,可以把它放置在任何你喜欢的文件夹,如果是像我样的菜鸟,建议把它放置到主文件夹(/home/*)下。
下面开始安装jdk:

终端下进入你存放jdk-6u12-linux-i586.bin,例如我的位置是:/home/liangshihong
更改文件权限为可执行
$ sudo chmod u+x jdk-6u12-linux-i586.bin

$ sudo -s ./jdk-6u12-linux-i586.bin
一路回车,直到询问是否安装,输入yes回车

ok,安装完毕,下面配置环境变量

配置classpath,修改所有用户的环境变量
$ sudo gedit /etc/profile
在文件最后添加

#set java environment 

这里需要修改安装的路径
JAVA_HOME=/home/liangshihong/jdk1.6.0_12

export JRE_HOME=/home/liangshihong/jdk1.6.0_12/jre

export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH

export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

重新启动计算机,用命令测试jdk的版本

java -version
这里需要用户模式下可以看到,root下没有环境变量
显示如下信息:成功安装

java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode)
liangshihong@liangshihong-Imagine:~$


Installing required packages (Ubuntu 10.04 -- 11.10)

这个也恶心,
lib32ncurses5-dev
是64bit系统的lib,所以按照下面的方式操作,不安着官方的操作


Building on Ubuntu 10.04-11.10 is no longer supported, but may be useful for building olderreleases of AOSP.

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \  libxml2-utils xsltproc

On Ubuntu 10.10:

$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

On Ubuntu 11.10:

$ sudo apt-get install libx11-dev:i386
安装一些工具包

        64-bit:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \  libxml2-utils xsltproc
32-bit
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \  zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev \  libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown \  libxml2-utils xsltproc

     On Ubuntu 10.10:

    $ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

     On Ubuntu 11.10:

    $ sudo apt-get install libx11-dev:i386
配置ccache(这里直接复制下面给出的文章的相关内容,感谢作者的分享)

ccache(“compiler cache”的缩写)是一个编译器缓存,该工具会高速缓存编译生成的信息,并在编译的特定部分使用高速缓存的信息, 比如头文件,这样就节省了通常使用cpp解析这些信息所需要的时间。如果您编译清单2中的文件,假定foobar.h中包含对其他头文件的引用,ccache会用那个文件的 cpp-parsed版本来取代include声明。ccache只是将最终的文本拷贝到文件中,使得它可以立即被编译,而不是真正去读取、理解并解释其内容。

这一步是可选的。我在编译的时候没有配置ccache,最后的编译时间用了尼玛至少六个小时以上,虽然目前我还没有尝试过配置ccache后的编译速度,这里还是建议读者配置一下,以节省编译时间,不要像我这么悲催。配置方法如下:
打开用户目录下的.bashrc,将下面语句添加到文件后面并保存退出:

我只配置了以下一句话,我的文件系统够大。并且都和主目录一样的

exportUSE_CCACHE=1

 默认情况下cache(缓存)会保存在~/.ccache目录下,如果主目录位于NFS或其他非本地文件系统上,也要将下面语句添加到.bashrc中,之后保存并退出:

export CCACHE_DIR=<path-to-your-cache-directory>

 将

<path-to-your-cache-directory>修改为cache目录的位置。

 推荐的cache目录大小为50-100GB,在命令行执行以下命令:(在下载的android的源码根目录执行)

prebuilt/linux-x86/ccache/ccache -M 20G

 该设置会保存到CCACHE_DIR中,且该命令是长效的,不会因系统重启而失效。

Configuring USB Access

配置USB按照官方的操作


Under GNU/linux systems (and specifically under Ubuntu systems),regular users can't directly access USB devices by default. Thesystem needs to be configured to allow such access.

The recommended approach is to create a file/etc/udev/rules.d/51-android.rules (as the root user) and to copythe following lines in it.<username> must be replaced by theactual username of the user who is authorized to access the phonesover USB.

# adb protocol on passion (Nexus One)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"# fastboot protocol on passion (Nexus One)SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"# adb protocol on crespo/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"# fastboot protocol on crespo/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"# adb protocol on stingray/wingray (Xoom)SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"# fastboot protocol on stingray/wingray (Xoom)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"# adb protocol on maguro/toro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"# fastboot protocol on maguro/toro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"# adb protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"# adb protocol on panda (PandaBoard ES)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"# fastboot protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"# usbboot protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"# usbboot protocol on panda (PandaBoard ES)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"# adb protocol on grouper/tilapia (Nexus 7)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"# fastboot protocol on grouper/tilapia (Nexus 7)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"# adb protocol on manta (Nexus 10)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"# fastboot protocol on manta (Nexus 10)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"

Those new rules take effect the next time a device is plugged in.It might therefore be necessary to unplug the device and plug itback into the computer.

This is known to work on both Ubuntu Hardy Heron (8.04.x LTS) andLucid Lynx (10.04.x LTS). Other versions of Ubuntu or othervariants of GNU/linux might require different configurations.




原创粉丝点击