首页 > 代码库 > Ubuntu12.04 64bit版本下载Android源码完整教程

Ubuntu12.04 64bit版本下载Android源码完整教程

    首先去官网http://source.android.com/source/initializing.html可以看到完整的安装教程。不过一般情况下,按照这个教程是无法一步到位的,因为中途肯定会遇到很多问题。这里我把我遇到的问题以及相应的解决方案总结一下:

   1、sudo apt-get install git 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 tofrodos \ python-markdown libxml2-utils xsltproc zlib1g-dev:i386

   遇到错误如下:

The following packages have unmet dependencies:
g++-multilib : Depends: gcc-multilib (>= 4:4.6.3-1ubuntu5) but it is not going to be installed
Depends: g++-4.6-multilib (>= 4.6.3-1~) but it is not going to be installed
libgl1-mesa-dev : Depends: mesa-common-dev (= 8.0.2-0ubuntu3) but it is not going to be installed
libgl1-mesa-glx : Depends: libglapi-mesa (= 8.0.2-0ubuntu3)
Recommends: libgl1-mesa-dri (>= 7.2)
libx11-dev : Depends: libxcb1-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

    这是因为当前系统的gcc版本过高引起的,我们需要将gcc版本降低到4.4,解决方法如下:

①安装低版本的gcc和g++
 使用gcc4.4 版本进行编译.首先安装低版本的gcc和g++
 sudo apt-get install gcc-4.4
 sudo apt-get install g++-4.4
 
 ②装完后进入到/usr/bin目录下,更改gcc,g++链接
 $ cd /usr/bin
 $ ls -l gcc*
lrwxrwxrwx 1 root root      7 Jan 10 18:19 gcc -> gcc-4.6
-rwxr-xr-x 1 root root 259232 Apr 16  2012 gcc-4.4
-rwxr-xr-x 1 root root 353216 Apr 16  2012 gcc-4.6

 发现gcc 链接到gcc-4.6,  需要将它改为链接到gcc-4.4 :
 $ sudo mv gcc gcc.bak                    ----先备份gcc-4.6
 $ sudo ln -s gcc-4.4 gcc

 同理,仍然在/usr/bin目录下
 $ ls -l g++*
lrwxrwxrwx 1 root root      7 Mar 14  2012 g++ -> g++-4.6
-rwxr-xr-x 1 root root 263328 Apr 16  2012 g++-4.4
-rwxr-xr-x 1 root root 357312 Apr 16  2012 g++-4.6
 
 需要将g++链接改为g++-4.4:
$ sudo mv g++ g++.bak                   ----先备份g++-4.6
$ sudo ln -s g++-4.4 g++
 
 再查看gcc和g++版本号:
$ gcc -v
$ g++ -v

 均显示gcc version 4.4,说明gcc 4.4安装成功。

③、gcc降到4.4后错误
a. 提示bits/predefs.h:没有那个文件或目录错误的
$ sudo apt-get install gcc-multilib 即可

b. g++: selected multilib ‘32‘ not installed错误
No private recovery resources for TARGET_DEVICE crespo
host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
g++: selected multilib ‘32‘ not installed
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp] Error 1
make: *** Waiting for unfinished jobs....
host SharedLib: libESR_Shared (out/host/linux-x86/obj/lib/libESR_Shared.so)
g++: selected multilib ‘32‘ not installed
make: *** [out/host/linux-x86/obj/lib/libESR_Shared.so] Error 1
g++: selected multilib ‘32‘ not installed
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1

解决:
$ sudo apt-get install g++-4.4-multilib

 

    2、sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so

    3、然后就是按照http://source.android.com/source/downloading.html里面的步骤一次执行。不过在使用命令

    repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1 和 repo sync

    的时候,可能会报错。出错了就需要将源码目录下的.repo整个文件夹删除,然后重新初始化和同步!注意:最好在命令前加上sudo 免得出现权限问题!!!

   4、现在就开始下载源代码了。慢慢等待吧~