Android4.0源码编译方法以及错误解决方案

from:http://blog.csdn.net/wanjun8659/article/details/8095664


历时一个星期,终于将android4.0源码编译成功,中间经历了各种曲折,非常之蛋疼,现在将编译方法共享一下:


Android源码编译步骤:

(基于ubuntu11.10和android4.0)

1.   安装JDK

2.   配置JDK环境变量

gedit /etc/environment

在打开的文件中,添加如下几行:

PATH=$PATH:$JAVA_HOME/bin($PATH为之前的PATH环境变量的内容)

CLASSPATH=".:$JAVA_HOME/bin"

JAVA_HOME="/usr/lib/jvm/java/jdk1.6.0_29"

接下来,需要安装java/javac/jar命令了,执行如下命令:

update-alternatives--install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_29/bin/java 300

update-alternatives--install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_29/bin/javac 300

update-alternatives--install /usr/bin/jar jar /usr/lib/jvm/java/jdk1.6.0_29/bin/jar 300

update-alternatives--config java

update-alternatives--config javac

update-alternatives--config jar

3.   将Android4.0源码拷贝至系统目录并解压缩(tar vxzf)

4.   安装需求包(注意安装顺序)

$ sudoapt-get install git-core gnupg flex bison gperf build-essential \

zip curlzlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \

x11proto-core-devlibx11-dev lib32readline5-dev lib32z-dev \

libgl1-mesa-devg++-multilib mingw32 tofrodos python-markdown \

libxml2-utilsxsltproc

$ sudoapt-get install libx11-dev:i386

5.   设置编译环境

onejune@ubuntu:/share/android4.0$source build/envsetup.sh

onejune@ubuntu:/share/android4.0$lunch full-eng

6.   开始编译

Sudomake �Cj4

7.   启动所编译的系统

编译完之后会在out/target/product/generic目录下生成system.imgramdisk.img userdata.img三个镜像文件。

在启动模拟器之前,需要先为模拟器系统设置环境变量,

执行gedit ~/.bashrc,新增环境变量如下:

exportANDROID_PRODUCT_OUT=/share/android4.0/out/target/product/generic

ANDROID_PRODUCT_OUT_BIN=/share/android4.0/out/host/linux-x86/bin

exportPATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};

8.   同步这些变化并启动模拟器:

$ source~/.bashrc

$ cd /share/android4.0/out/target/product/generic

$emulator -system system.img -data userdata.img -ramdisk ramdisk.img


Android编译错误处理:


错误代码

解决方法

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../libncurses.so when searching for -lncurses

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../libncurses.a when searching for -lncurses

/usr/bin/ld: skipping incompatible /usr/lib/libncurses.so when searching for -lncurses

/usr/bin/ld: skipping incompatible /usr/lib/libncurses.a when searching for -lncurses

/usr/bin/ld: cannot find -lncurses

collect2: ld returned 1 exit status


make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1

apt-get install lib32ncurses5-dev

make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl]

Error 1 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libstdc++.so when searching for -lstdc++

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libstdc++.a when searching for -lstdc++

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libstdc++.so when searching for -lstdc++

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libstdc++.a when searching for -lstdc++

/usr/bin/ld: cannot find -lstdc++ collect2: ld returned 1 exit status


其找不到libstdc++

apt-get install g++-multilib

-o out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt -lz -lrt

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../libz.so when searching for -lz

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../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


其找不到libz

apt-get install lib32z1-dev

致命错误: zlib.h:没有那个文件或目录

执行  sudo apt-get install zlib1g-dev

致命错误: jpeglib.h:没有那个文件或目录

执行  sudo apt-get install libjpeg-dev

致命错误: png.h:没有那个文件或目录

执行  sudo apt-get install libpng

致命错误: curses.h:没有那个文件或目录

sudo apt-get  install libncurses5-dev

致命错误: ft2build.h:没有那个文件或目录

sudo apt-get install libxft2-dev

致命错误: GL/glx.h:没有那个文件或目录 和   致命错误: X11/extensions/shape.h:没有那个文件或目录

sudo apt-get install libgl1-mesa-dev

/usr/bin/ld: cannot find -lGL

先删掉/usr/lib/i386_linux-gnu/libGL.so,然后

sudo ln -s /usr/lib/i386_linux-gnu/mesa/libGL.so.1 /usr/lib/i386_linux-gnu/libGL.so

一定要确保/usr/lib/i386_linux-gnu/libGL.so的链接目标是i386_linux-gnu/mesa/libGL.so.1

/bin/bash: java: command not found  

sudo ln -s  /usr/java/jdk1.6.0_35/bin/jar /bin/jar

sudo ln -s /usr/java/jdk1.6.0_35/bin/java /bin/java

sudo ln -s /usr/java/jdk1.6.0_35/bin/javac /bin/javac

sudo ln -s /usr/java/jdk1.6.0_35/bin/javah /bin/javah

sudo ln -s /usr/java/jdk1.6.0_35/bin/javadoc /bin/javadoc

Java: NFCDemo (out/target/common/obj/APPS/NFCDemo_intermediates/classes)

collect2: ld terminated with signal 9 [Killed]

将虚拟机内存调整为2G或者更多

NAND:could not open file system.img

Sudo chomod 777 system.img




你可能感兴趣的:(java,android,解决方案,的)