Ubuntu12.04 64位下,下载编译Android 2.3源码
Ubuntu12.04 64位下,下载编译Android 2.3源码
1、下载
源码可以在google官方下载到,但是确实太慢了。我在http://www.verycd.com/topics/2906182/ 下载的,感谢上传者。
对于在官网下载的童鞋来说,其官方文档写得还是很清楚http://source.android.com/source/downloading.html
大致过程如下:
创建目录文件夹
$ mkdir ~/bin
$ PATH=~/bin:$PATH
下载repo
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
创建工作目录
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY
初始化repo
$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
对于下载不同版本的android,只需要指明android对应的版本,对于2.3版本,将命令修改为
$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.3_r1
下载源码
$ repo sync
这其中,可能遇到的问题,只有自己百度了。
2、编译
编译环境搭建,查看官方文档http://source.android.com/source/initializing.html
l 安装jdk6
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
需要注意的是:
n 1、jdk6找不到
E: Package 'sun-java6-jdk' has no installation candidate
解决:
添加这个源:
sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse”
n Jdk安装时的ok键,使用键盘左右键进行选中。
l 依赖环境:
$ 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-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
安装过程中,我出现了错误1。解决后:
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
l 编译
进入源码目录后,执行如下命令:
$ source build/envsetup.sh
$ lunch full-eng
$ make
编译过程中出现了错误2、3、4、5.
l 运行
$ emulator
错误:
1、安装全部库时libc6-dev:i386
错误:
Errors were encountered while processing:
libc6-dev:i386
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@mao-virtual-machine:~# apt-get install libc6-dev:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
libc6-dev:i386 is already the newest version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
libc6-dev:i386 : Depends: linux-libc-dev:i386 but it is not going to be installed
Recommends: gcc:i386 but it is not going to be installed or
c-compiler:i386
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
root@mao-virtual-machine:~# apt-get install linux-libc-dev:i386
root@mao-virtual-machine:~# apt-get install libc6-dev:i386
root@mao-virtual-machine:~# 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-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
2、错误:/usr/bin/ld: cannot find -lz
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/http://www.cnblogs.com/../libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/http://www.cnblogs.com/../libz.a when searching for -lz
/usr/bin/ld: skipping incompatible //usr/lib/libz.so when searching for -lz
/usr/bin/ld: skipping incompatible //usr/lib/libz.a when searching for -lz
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1
缺少lib32z1-dev,安装即可:apt-get install lib32z1-dev
3、编译选项[-fpermissive]
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
修改mk文件:
$ gedit frameworks/base/libs/utils/Android.mk
将:LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
改为:LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
需要注意的是:–fpermissive 前边的-是带输入法的,改为不带输入法的 短线就可以了
4、GCC版本过高
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
原因:
此处编译错误是由于ubuntu 11.10采用了GCC4.6.1导致的。
解决方法:
使用gcc4.4 版本进行编译.
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
装完后在/usr/bin目录下
$ ls -l gcc*
lrwxrwxrwx 1 root root 7 2011-10-29 09:11 gcc -> gcc-4.6
-rwxr-xr-x 1 root root 224544 2011-10-06 05:47 gcc-4.4
-rwxr-xr-x 1 root root 302104 2011-09-17 05:43 gcc-4.6
发现gcc 链接到gcc-4.6, 需要将它改为链接到gcc-4.4 :
sudo mv gcc gcc.bak
sudo ln -s gcc-4.4 gcc
同理
ls -l g++*
lrwxrwxrwx 1 root root 7 2011-08-14 15:17 g++ -> g++-4.6
-rwxr-xr-x 1 root root 228640 2011-10-06 05:45 g++-4.4
-rwxr-xr-x 1 root root 306200 2011-09-17 05:39 g++-4.6
需要将g++链接改为g++-4.4:
/usr/bin$ sudo mv g++ g++.bak
/usr/bin$sudo ln -s g++-4.4 g++
再查看gcc和g++版本号:
gcc -v
g++ -v
均显示gcc version 4.4,说明gcc 4.4安装成功。
5、gcc降到4.4后错误
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
host Executable: obbtool (out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/obbtool)
g++: selected multilib '32' not installed
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/obbtool] Error 1
解决:
sudo apt-get install g++-4.4-multilib