1. 用vmware安装ubuntu14.04 64位系统,处理器数量设置为2,硬盘设置为70GB.
1.1 更新源
sudo cp /etc/apt/sources.list/etc/apt/sources.list.bak
sudo gedit /etc/apt/sources.list
删除原有源
添加阿里源
deb http://mirrors.aliyun.com/ubuntu/trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/trusty-backports main restricted universe multiverse
更新
sudo apt-get update
2. 下载android-4.0.3_r1源码。
2.1 创建bin目录,并添加到环境变量
$ mkdir ~/bin
$ PATH=~/bin:$PATH
2.2 下载Repo工具
$ curlhttps://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
2.3 创建工作目录
$ mkdir android-4.0.3_r1
$ cd android-4.0.3_r1
2.4 配置姓名和邮箱
$ git config --global user.name"liguangzhi"
$ git config --global user.email "liguangzhi@163.com"
2.5 更新最新版本Repo
$ repo init -u https://android.googlesource.com/platform/manifest-b android-4.0.3_r1
2.6 下载android源码树
$ repo sync
3. 准备编译环境
3.1 降低gcc/g++版本
将其改为4.4
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
cd /usr/bin
ls -l gcc*
sudo mv gcc gcc.bak
sudo ln -s gcc-4.4 gcc
ls -l g++*
sudo mv g++ g++.bak
sudo ln -s g++-4.4 g++
gcc -v
g++ -v
sudo apt-get install g++-4.4-multilib
3.1 卸载open jdk
3.2 oracle官网下载jdk-6u38-linux-x64.bin
3.3 解压
$ ./jdk-6u38-linux-x64.bin
3.4 配置环境变量
gedit ~/.bashrc
export JAVA_HOME=/home/lu/jdk
export JRE_HOME=/home/lu/jdk/jre
exportCLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
exportPATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source ~/.bashrc
3.5 检查安装
3.6 重新安装 jdk
$ sudo add-apt-repository "debhttp://archive.canonical.com/ lucid partner"
$ sudo apt-get update
4. 编译源码
4.1 初始化编译环境
$ sudo chmod -R 777 ./android-4.0.3_r1
$ source build/envsetup.sh
4.2 选择需要编译的版本类型
$ lunch full-eng
4.3 开始编译
$ make –j4
4为cpu的核心数
编译过程
编译完成
I5、8G机器满负荷运行,编译2小时
System.img大小为173.5MB.
5. 模拟运行
$ source build/envsetup.sh
$ lunch full-eng
$ emulator
6. 编译错误及解决方法
问 题:asm/errno.h: No such file or directory
解决方法: 64位: sudo apt-get install linux-libc-dev
32位: sudo apt-get install linux-libc-dev:i386
问 题:/usr/bin/ld: cannot find -lz
解决方法: 64位: sudo apt-get install zlib1g-dev
32位: sudo apt-get install lib32z1-dev
问 题: /bin/bash:bison: command not found
解决方法: sudo apt-get install bison
问 题: /bin/bash:flex: command not found
解决方法: sudo apt-get install flex
问 题:usr/bin/ld: cannot find libncurses.so.5
解决方法: sudo apt-get install lib32ncurses5-dev
问 题:dalvik/vm/native/dalvik_system_Zygote.cpp:222:43: error: ‘setrlimit’ was notdeclared in this scope err
解决方法:
在dalvik/vm/native/dalvik_system_Zygote.cpp中间增加一个头文件#include<sys/resource.h>
#include "Dalvik.h"
#include"native/InternalNativePriv.h"
#include <sys/resource.h>
问 题: fatalerror: X11/Xlib.h: No such file or directory
解决方法: sudo apt-get install libx11-dev:i386(安装32位)
问 题: out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/main.o:undefined reference to symbol 'XInitThreads'//usr/lib/i386-linux-gnu/libX11.so.6: error adding symbols: DSO missing fromcommand line collect2: ld returned 1exit status
解决方法: 修改development/tools/emulator/opengl/host/renderer/Android.mk文件
添加一行:LOCAL_LDLIBS += -lX11
问 题:/usr/include/zlib.h:34: fatal error: zconf.h: No such file or directory
解决方法: lib1g-dev有zconf.h头文件修改了路径,放到了/usr/include/x86_64-Linux-gnu/,将其拷贝到/usr/include/下即可
问 题: GL/glx.h:No such file or directory. compilation terminated.
解决方法: sudo apt-get install libgl1-mesa-dev
问 题: cannotfind -lGL
解决方法: sudo apt-get install libgl1-mesa-glx:i386
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
问 题: sh: 1:gperf: not found
解决方法: sudo apt-get install gperf
问 题: Can'tlocate Switch.pm in @INC
解决方法: sudo apt-get install libswitch-perl