- 【0】初始化工作:cd到源代码的根目录后,执行下面的命令
$ source build/envsetup.sh
- 【1】选择想要编译的类型:下面是一个example
$ lunch full-eng
这意味着,你需要编译一个带有所有语言,输入法,apps,并且具备debug功能的ROM(for emulator)。(full代表了编译名,eng代表了编译类型)关于其他的编译类型,参见下表:
Build name | Device | Notes |
---|---|---|
full | emulator | fully configured with all languages, apps, input methods |
full_maguro | maguro | full build running on Galaxy Nexus GSM/HSPA+ ("maguro") |
full_panda | panda | full build running on PandaBoard ("panda") |
Buildtype | Use |
---|---|
user | limited access; suited for production |
userdebug | like "user" but with root access and debuggability; preferred for debugging |
eng | development configuration with additional debugging tools |
- 【2】开始编译源代码:
$ make -j16
- 【3】可能遇到的问题:
(1)依赖问题:请确保你有按照下面的步骤搭建编译环境:
Installing the JDK
- 请确保安装的是sun的JDK,不能使用openJDK,不然后面也会出现编译错误
- 有可能提示找不到sun-java6-jdk,那么请参考Linux(ubuntu)下搭建Java开发环境 - 安装JDK
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
Installing required packages (Ubuntu 10.04 -- 11.10)
- 请使用64-bit的系统:推荐使用10.04
$ 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
- 如果你使用的是Ubuntu 12.04:(经过验证,下面的包有些是已经废弃了的,你可以根据命令行的提示进行替换安装)
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386 \
g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown \
libxml2-utils xsltproc zlib1g-dev:i386
(2)gcc与g++版本问题:
如果你的gcc与g++版本是4.6,请按照下面的方法安装4.4,最新的版本gcc与g++会出现编译不过的问题。
- sudo apt-get install gcc-4.4 //安装gcc-4.4版本
- sudo apt-get install g++-4.4 //安装g++-4.4版本
- sudo mv /usr/bin/gcc /usr/bin/gcc.bak //备份原始gcc
- sudo ln -s /usr/bin/gcc-4.4 /usr/bin/gcc //建立Link
- sudo mv /usr/bin/g++ /usr/bin/g++.bak //备份原始g++
- sudo ln -s /usr/bin/g++-4.4 /usr/bin/g++ //建立Link
- sudo apt-get install g++-4.4-multilib //安装g++-4.4-multilib