1、编译环境准备
下载android代码需要大约需要8.5G,单独编译一套代码需要30G左右,多套的话硬盘空间至少需要100G以上。
2. 配置android在Linux下的编译环境
安装编译所需的软件包:
1 | $ |
2 | $ |
3 |
|
Python2.6-2.7,download from http://www.python.org/download/ (Ubuntu12.04一般自带)。
3.安装JDK
在Ubuntu下安装JDK比较简单,可以在软件中心直接搜索安装,也可以按以下方法安装:
安装Java 6(android2.3或更新的版本4.0以上等)
$ sudo add-apt-repository"deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
安装Java 5(amdroid2.3之前Froyo版本和更老的版本)
$ 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
4、配置ccache
你可以选择是否搭建使用ccache编译器缓存设置。Ccache充当一个编译器缓存,可以用来加速再次编译。这招很管用,如果你经常需要清理环境或如果你频繁切换不同的构建产品来多次编译,这样设置后使之重复编译的时间缩短。
$vi ~/.bashrc
export USE_CCACHE=1 //系统默认存放在~/.ccache
export CCACHE_DIR=<path-to-your-cache-directory> //建议设置大小为50-100GB
$ source ~/.bashrc
在你下载完代码后,执行下面的命令
prebuilts/misc/linux-x86/ccache/ccache -M 50G
如果编译的版本为android4.0即Ice Cream Sandwich (4.0.x),执行下面的命令
prebuilt/linux-x86/ccache/ccache-M50G
配置好后,这些设置会一直保留
5.Android 编译报错(环境问题)QA:
Question:
make[3]: *** [arch/arm/boot/uImage] Error 1
make[2]: *** [uImage] Error 2
make[1]: *** [sub-make] Error 2
selected multilib '32' not installed
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl] Error 1
make: *** Waiting for unfinished jobs....
make: *** [out/host/linux-x86/obj/lib/libESR_Portable.so] Error 1
Answer:
make: *** [out/host/linux-x86/obj/EXECUTABLES/sqlite3_intermediates/sqlite3] Error 1
make: *** Waiting for unfinished jobs....
Answer:
sudo apt-get install libreadline6-dev lib32readline6-dev
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp.o] 错误 1
Answer:
sudo apt-get install libc6-dev-i386
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp] error 1
Answer:
sudo apt-get install g++-multilib
external/clearsilver/cgi/cgi.c:22: fatal error: zlib.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_cgi_intermediates/cgi.o] Error 1
Answer:
sudo apt-get install zlib1g-dev
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1
Answer:
sudo apt-get install lib32z1-dev/bin/bash: bison: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
Answer:
sudo apt-get install bison/bin/bash: flex: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
Answer:
sudo apt-get install flexcollect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1
Answer:
sudo apt-get install lib32ncurses5-devcompilation terminated.
make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_intermediates/android/main-common.o] Error 1
Answer:
sudo apt-get install libx11-devcalling gperf failed: 32512 at ./makeprop.pl line 96.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/WebCore/css/CSSPropertyNames.h] Error 25
make: *** Deleting file `out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/WebCore/css/CSSPropertyNames.h'
6.android 官方资料:
http://source.android.com/source/initializing.html#installing-required-packages-ubuntu-1204