1、编译环境准备
下载Android代码需要大约需要8.5G,单独编译一套代码需要30G左右,多套的话硬盘空间至少需要100G以上。
2. 配置android在Linux下的编译环境
安装编译所需的软件包:
1 $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-glx libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev lib32readline6-dev gcc-4.4 g++-4.4 g++-4.4-multilib gcc-4.4-multilib
2 $ sudoln -s /usr/lib/i386-linux-gnu/libX11.so.1 /usr/lib/i386-linux-gnu/libX11.so
3 $cd /usr/bin/
$sudomv gcc gcc.bak
$sudo ln -s gcc-4.4 gcc
$sudomv g++ g++.bak
$sudo ln -s g++-4.4 g++
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 //系统默认存放在~/.ccacheexport 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-M 50G
配置好后,这些设置会一直保留
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-11/92232p2.htm
推荐阅读:
Android ROM开发之Android源码搭建与编译 http://www.linuxidc.com/Linux/2013-11/92207.htm
Ubuntu 12.04 编译Android 4.0.3 的环境配置 http://www.linuxidc.com/Linux/2012-11/73918.htm
5.Android 编译报错(环境问题)QA:
Question:
g++: g++: selected multilib ’32’ not installed
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:
sudo apt-get install g++-4.4-multilib gcc-4.4-multilib
Question:
/usr/bin/ld: cannot find -lreadline
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
Question:
/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
Question:
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp] error 1
Answer:
sudo apt-get install g++-multilib
Question:
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
Question:
/usr/bin/ld: cannot find -lz
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
Question:
bison -d -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
/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
Question:
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
/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 flex
Question:
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1
Answer:
sudo apt-get install lib32ncurses5-dev
Question:
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:55: fatal error: X11/Xlib.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_intermediates/android/main-common.o] Error 1
Answer:
sudo apt-get install libx11-dev
Question:
sh: gperf: not found
calling 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’
Answer:
sudo apt-get install gperf
6.android 官方资料:
http://source.android.com/source/initializing.html#installing-required-packages-Ubuntu-1204
更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11