Ubuntu12.04编译Android2.3.4

时间:2021-11-10 14:35:15

Ubuntu12.04编译Android2.3.4

1.下载Ubuntu
ubuntu-12.04-dvd-i386.iso
2.使用U盘安装,启动盘制作用unetbootin-windows-568工具即可
3.虚拟机用的是VMware-workstation-full-8.0.2-591240.exe破解版本,或者直接安装在机器上
4.虚拟机安装vmware tools  
打开虚拟机,点击install vmware tools
把 vmware tools拖到桌面上(命令复制时由于有空格 需要添加双引号“”),ctrl+alt+t进入终端,输入sudo su 输入密码获取root权限,然后把vmware tools CP到/tmp中tar vzxf vmwaretools解压后到 vmware-tools-distrib里面输入./vmware-install.pl安装,根据提示到出现enjoy,--the vmware team就成功安装了。
可以通过在终端中输入如下命令来运行它: 
$ /usr/bin/vmware-toolbox 
或者让vmware-toolbox实现开机自动运行。
点击Ubuntu菜单:System——首选项——会话—— Startup Programs,Add一个Name叫“vmware-toolbox”,Command是“/usr/bin/vmware-toolbox”的启动程序。这样每次开机后就能自动运行VMware Tools了
5.更新源
sudo cp /etc/apt/sources.list /etc/apt/sources.list_back (这是备份源列表) 
sudo gedit /etc/apt/sources.list   (这是编辑源列表)
sudo cp /etc/apt/sources.list_backup /etc/apt/sources_list(恢复源列表)
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install ubuntu-restricted-extras
一些常用的源列表:
deb http://cn.archive.Ubuntu.com/ubuntu/ natty multiverse
deb-src http://cn.archive.Ubuntu.com/ubuntu/ natty multiverse
deb http://cn.archive.Ubuntu.com/ubuntu/ natty-updates multiverse
deb-src http://cn.archive.Ubuntu.com/ubuntu/ natty-updates multiverse
deb http://security.Ubuntu.com/ubuntu natty-security main restricted
deb-src http://security.Ubuntu.com/ubuntu natty-security main restricted
deb http://security.Ubuntu.com/ubuntu natty-security universe
deb-src http://security.Ubuntu.com/ubuntu natty-security universe
deb http://security.Ubuntu.com/ubuntu natty-security multiverse
deb-src http://security.Ubuntu.com/ubuntu natty-security multiverse
deb http://archive.canonical.com/Ubuntu natty partner
deb-src http://archive.canonical.com/Ubuntu natty partner
*源
deb http://tw.archive.Ubuntu.com/ubuntu/ natty main universe restricted multiverse
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty main universe restricted multiverse
deb http://tw.archive.Ubuntu.com/ubuntu/ natty-security universe main multiverse restricted
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty-security universe main multiverse restricted
deb http://tw.archive.Ubuntu.com/ubuntu/ natty-updates universe main multiverse restricted
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty-updates universe main multiverse restricted
网易源(速度很快)
deb http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
上海源
deb http://mirror.rootguide.org/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirror.rootguide.org/Ubuntu/ natty main universe restricted multiverse
deb http://mirror.rootguide.org/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirror.rootguide.org/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirror.rootguide.org/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirror.rootguide.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirror.rootguide.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirror.rootguide.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirror.rootguide.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirror.rootguide.org/Ubuntu/ natty-updates universe main multiverse restricted
搜狐源
deb http://mirrors.shlug.org/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirrors.shlug.org/Ubuntu/ natty main universe restricted multiverse
deb http://mirrors.shlug.org/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-updates universe main multiverse restricted
6.Android版本代号
Code name  Version    API level 
(no code name)   1.0    API level 1 
(no code name)   1.1    API level 2 
Cupcake   1.5    API level 3, NDK 1 
Donut    1.6    API level 4, NDK 2 
Eclair    2.0          API level 5 
Eclair                  2.0.1    API level 6 
Eclair    2.1                     API level 7, NDK 3 
Froyo    2.2.x    API level 8, NDK 4 
Gingerbread   2.3 - 2.3.2   API level 9, NDK 5 
Gingerbread   2.3.3 - 2.3.7   API level 10 
Honeycomb   3.0    API level 11 
Honeycomb   3.1    API level 12, NDK 6 
Honeycomb   3.2.x    API level 13 
IceCreamSandwich  4.0.1 - 4.0.2   API level 14, NDK 7 
IceCreamSandwich  4.0.3 - 4.0.4   API level 15

7.Android编译环境配置
vim ~/.bashrc添加:
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_32 
export JRE_HOME=${JAVA_HOME}/jre
export HOME_BIN=~/bin/
export CLASSPATH=.:${JAVA_HOME}/lib:$JRE_HOME/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export ANDROID_SDK_HOME=/home/xch/bin/out/host/linux-x86/sdk/android-sdk_eng.xch_linux-x86
export ANDROID_PRODUCT_OUT=/home/xch/bin/out/target/product/generic
export PATH=${PATH}:${JAVA_PATH}:${HOME_BIN}:${ANDROID_SDK_HOME}/tools

默认的PATH,防止修改PATH后出错,可以用来修正
export   PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
修改完后source ~/.bashrc一下就可以了

8.Android源码下载
可参考官方文档:http://source.android.com/source/downloading.html
可能需要预先安装一些软件:
sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
sudo apt-get install make
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install libc6-dev
sudo apt-get install patch
sudo apt-get install texinfo
sudo apt-get install zlib1g-dev
sudo apt-get install valgrind
sudo apt-get install python2.5(或者更高版本)
sudo apt-get install curl
sudo apt-get install sun-java5-jdk或者1.6

$ mkdir ~/bin
$ PATH=~/bin:$PATH(这一步在前面环境变量那里设置了)
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
repo init -u https://android.googlesource.com/platform/manifest  -b android-2.3.4_r1
repo sync

如果下载源码出现被拒绝的错误,可以google一下解决方法,下面是其中一个解决方法:
curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo" > ~/bin/repo  
chmod a+x ~/bin/repo  
PATH=~/bin:$PATH  
mkdir WORKING_DIRECTORY  
cd WORKING_DIRECTORY  
//repo init -u git://codeaurora.org/platform/manifest.git -b gingerbread  
repo init -u git://codeaurora.org/platform/manifest.git -b android-2.3.4_r1
repo sync
然后漫长的等待......
9.编译源码
32位机要修改下面的文件:
build/core/main.mk
        ifeq ($(BUILD_OS),linux)
build_arch := $(shell uname -m) 
---ifneq (64,$(findstring 64,$(build_arch))) 
+++ifneq (i686,$(findstring i686,$(build_arch)))
$(warning
************************************************************)
$(warning You are attempting to build on a 32-bit system.)
 $(warning Only 64-bit build environments are supported beyond
froyo/2.2.)
(--- means delete that line, +++ means add that line)
and change the code in four mk files below from “+=-m64” to “+=-m32”
external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk        
LOCAL_CFLAGS += -m32
LOCAL_LDFLAGS += -m32

编译过程中出现下面2个问题及解决方法:
1.[out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] error  1
$ gedit frameworks/base/libs/utils/Android.mk
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)改为:LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
2.make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]   error 1
/build/core/combo/HOST_linux-x86.mk
HOST_GLOBAL_CFLAGS
+= -D_FORTIFY_SOURCE=0
修改为:
HOST_GLOBAL_CFLAGS
+= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
然后就可以编译了:
$make -j2(使用2个线程编译)漫长的等待....
编译SDK
$make PRODUCT-sdk-sdk(又是漫长的等待....)
成功后可用模拟器测试:
$emulator