Android 源码编译make的错误处理

Android源码下载:官方下载 或参考android源码下载方式

Android编译版本: PLATFORM_VERSION=4.0.1(最新Android 4.0.1)

OS 操作系统平台: Linux yanggang 2.6.35-30-generic #61-Ubuntu SMP Tue Oct 11 15:29:15 UTC 2011 i686 GNU/Linux(Ubuntu10.10  32bit)


首先,我们先安装一些常用的工具
curl: 
sudo  apt-get  install  curl

git: sudo  apt-get  install  git

g++: sudo  apt-get  install  g++


然后,make遇到缺什么就安装什么


/usr/bin/ld: cannot find -lz

host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1
解决方法: sudo apt-get install zlib1g-dev    sudo apt-get install lib64z1-dev

/bin/bash: bison: command not found

Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
bison -d  -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
/bin/bash: bison: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
解决方法:sudo apt-get install bison


/bin/bash: flex: command not found

out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp: In function ‘int yyparse()’:
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1827: warning: deprecated conversion from string constant to ‘char*’
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1970: warning: deprecated conversion from string constant to ‘char*’
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
/bin/bash: flex: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
解决方法: sudo apt-get install flex


/usr/bin/ld: cannot find -lncurses

host Executable: adb (out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb)
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1

解决方法:sudo apt-get install libncurses5-dev


fatal error: GL/glx.h: No such file or directory

development/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp:22: fatal error: GL/glx.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libGLcommon_intermediates/GLDispatch.o] Error 1

解决方法:sudo apt-get install libgl1-mesa-dev


sh: gperf: not found

target Generated: libwebcore <= external/webkit/Source/JavaScriptCore/create_regex_tables
Generating CSSPropertyNames.h <= CSSPropertyNames.in
sh: gperf: not found
calling gperf failed: 32512 at ./makeprop.pl line 140.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h] Error 25
make: *** Deleting file `out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h'

解决方法:sudo apt-get install gperf



上述安装,可以用一条命令完成:

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
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
详见:   Initializing a Build Environment (android)



make编译源码的错误处理:


当前Java版本高于指定版本或不是规范的Java JDK(如OpenJDK),输入“java  -version”查看JDK版本:


从上图发现,的确是由前面一键安装时安装了 openjdk-6-jdk,有两种方式可以解决:


1) 配置规范的Java SDK

下载: jdk-6u20-linux-i586.bin

解压: ./jdk-6u20-linux-i586.bin

拷贝: mv jdk1.6.0_20 /home/homer/eclipse/

配置: sudo  vi  /etc/profile

export JAVA_HOME=/home/homer/eclipse/jdk1.6.0_20
export JRE_HOME=/home/homer/eclipse/jdk1.6.0_20/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

查看验证,如下图:




2) 卸载openjdk,重新安装jdk

a)卸载openjdk

点击左上角“ubuntu“的logo, 输入 “ubuntu software center”,查找软件中心管理

然后,选择“Installed”, 输入“openjdk”, 查找已安装的 openjdk,如下图:


选择“Remove”,卸载openjdk


b)重新安装jdk

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk



其实,除了上述两种解决方法外,如果当前JDK版本是规范的JDK 1.6以上(如:jdk1.7.0_05,我默认用的jdk版本),也会报错说不是正确的版本。

仔细分析Makefile文件,发现其依赖关系如下: 

Makefile —> build/core/main.mk —> 进行了jdk的版本判断, 脚本代码如下图:


从上图,分析代码,不难看出“openjdk“ 和 “jdk1.7.0_05” 版本编译不通过的原因了吧。。。。

(1) 如果“java -version” 中包含了“openjdk”,则 “$(shell java -version 2>&1 | grep -i openjdk)” 过滤的“openjdk”不会为空,自然其与空不等,即ifneq条件成立,因此执行“java_version :="  设置为空

(2) 如果是(1)情况,java_version为空, 自然输出错误提示信息; 如果“java -version”包含了“jdk1.7.0_05”而不是“xx1.6xx“字样,第一行过滤出来的java_version也是为空,结果也输出错误提示信息。


找出了问题,那该又如何解决呢? 知道了原理,问题就简单了(如果你和我一样使用的是“jdk1.7.0_05“及以上的1.7版本)

修改 '^java .*[ "]1\.6[\. "$$]'    '^java .*[ "]1\.7[\. "$$]'



最后,编译Android源码:

make  -j4


参考推荐:

Android Source Download(google)

Android Source Building(google)

Initializing a Build Environment(google)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值