【转】Android 源码编译make的错误处理--不错

原文网址:http://blog.csdn.net/ithomer/article/details/6977386

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)

 

自己补充:

(1)/usr/bin/ld: can't find lz

/usr/bin/ld: can't find ltinfo

/usr/bin/ld: can't find lncurse

本机ubuntu是64位的,默认安装的zlib-dev, libtinfo5-dev, libncurse5-dev都是64位版本,android源码需要这几个库的针对32位系统的版本(很奇怪!!!)

即lib32zl-dev, lib32tinfo5-dev, lib32ncurse5-dev

(2)

target thumb C++: gralloc.goldfish <= development/tools/emulator/opengl/system/gralloc/gralloc.cpp
development/tools/emulator/opengl/system/gralloc/gralloc.cpp:790: sorry, unimplemented: non-trivial designated initializers not supported
development/tools/emulator/opengl/system/gralloc/gralloc.cpp:790: sorry, unimplemented: non-trivial designated initializers not supported
development/tools/emulator/opengl/system/gralloc/gralloc.cpp:790: warning: missing initializer for member 'gralloc_module_t::reserved_proc'
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/gralloc.goldfish_intermediates/gralloc.o] Error 1

c/c++初始化乱序

代码里面的初始化跟下面的描述一样
C++风格的乱序初始化方式跟 C风格的一样,只是它更常用在C++代码里。
eg:
        struct User oneUser = {
                               name:"Lucy", 
                               id:10,
                               home:"/home/Lucy"
                              };

乱序这种方式在gcc/g++中,后缀名位.c可以支持;但是后缀名为.cpp就不支持,提示
sorry, unimplemented: non-trivial designated initializers not supported

解决方法:
在android源码的根目录中执行./build-android,而不是make -j4

 

posted on 2015-03-04 23:27  wi100sh  阅读(1202)  评论(0编辑  收藏  举报

导航