细致入微!汇总了make的各类错误解决方法

发布于:2022-12-10 ⋅ 阅读:(9319) ⋅ 点赞:(7)

问题:

You are attempting to build with the incorrect version of java. 
Your version is: java version "1.6.0_22".
The correct version is: Java SE 1.6.

查了一下现在已安装的 java:

java -versionjava version "1.6.0_22"OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.2)OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

解决办法如下:

1. 从 java 官方地址 http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html 下载 Java SE Development Kit 6 Update 45 文件。

2. 移到 /usr/lib/java 目录下执行

chmod a+x jdk-6u45-linux-amd64.bin 
sudo ./jdk-6u45-linux-amd64.bin   

添加环境变量

sudo gedit /etc/profile

在文件最后添加

#set java environment
export JAVA_HOME= /usr/lib/java/jdk1.6.0_45
export JRE_HOME= /usr/lib/java/jdk1.6.0_45/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

最后使环境变量生效

source /etc/profile

Ubuntu 系统默认安装并使用 OpenJDK (usr/lib/jvm/),因此需要手动修改系统默认的 JDK,

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/java/jdk1.6.0_45/bin/javac 300

sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jdk1.6.0_45/bin/java 300
sudo update-alternatives --config javac

,再选择相应的 Priority 300

sudo update-alternatives --config java

,再选择相应的 Priority 300

至此配置完成,输入 java -version、javac 或 java 检查是否配置成功。

首先,我们先安装一些常用的工具
curl: 

sudo  apt-get  install  curl

git: 

sudo  apt-get  install  git

g++: 

sudo  apt-get  install  g++

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

/usr/bin/ld: cannot find -lz

host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: cannot fi
nd -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 

或 

sudo apt-get install libncurses5-dev:i386

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

编译 Android 源码,按照 installing-required-packages-ubuntu-1204 提供方法先安装必要的工具。

以下是编译 Android 4.0.3 的常见错误,这些错误的解决办法收录自互联网。

Google group 有个专门的 Android Building 组,有兴趣的可以加入。

Fix 1 

Error:

frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<android::String8, android::sp<AaptDir> >’ are not found by unqualified lookup

frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead

make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/AaptAssets.o] Error 1

Fix:

vi frameworks/base/tools/aapt/Android.mk

Add '-fpermissive' to line 31:

LOCAL_CFLAGS += -Wno-format-y2k -fpermissive



Fix 2

Error:

frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<android::String8, android::wp<android::AssetManager::SharedZip> >’ are not found by unqualified lookup


frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead

make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/AssetManager.o] Error 1

Fix:

vi frameworks/base/libs/utils/Android.mk



Add '-fpermissive' to line 64:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive


Fix 3.

Error:
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
<命令行>:0:0: 错误: “_FORTIFY_SOURCE” 重定义 [-Werror]
frameworks/base/tools/obbtool/Main.cpp:1:0: 附注: 这是先前定义的位置


make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] 错误 1

Fix:

vi build/core/combo/HOST_linux-x86.mk    

line56
Add  -U_FORTIFY_SOURCE

HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0


Fix 4 

Error:
development/tools/emulator/opengl/host/tools/emugen/main.cpp:79:9: error: ‘optind’ was not declared in this scope
development/tools/emulator/opengl/host/tools/emugen/main.cpp:92:45: error: ‘optind’ was not declared in this scope
make: *** [out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o] Error 1


Fix:

vi development/tools/emulator/opengl/host/tools/emugen/main.cpp



Add

'#include <getopt.h>' to list of includes:
#include <getopt.h>



Fix 5


Error:
host C++: liboprofile_pp <= external/oprofile/libpp/arrange_profiles.cpp
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1


Fix:

vi external/oprofile/libpp/format_output.h

Remove 'mutable' from 'mutable counts_t & counts;' on line 94:
counts_t & counts;



 Fix 6 

Error:
development/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp:345:65:   required from here


frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<unsigned int, ShaderData*>’ are not found by unqualified lookup


frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead

make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o] Error 1

Fix:

vi development/tools/emulator/opengl/Android.mk
Add '-fpermissive' to line 25:
EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive



 Fix 7 

Error:
/usr/bin/ld: note: 'XInitThreads' is defined in DSO /lib/libX11.so.6 so try adding it to the linker command line
/lib/libX11.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer] Error 1


Fix:

vi development/tools/emulator/opengl/host/renderer/Android.mk


Add new entry 'LOCAL_LDLIBS += -lX11' after line 6 as shown:

LOCAL_SRC_FILES := main.cpp
LOCAL_CFLAGS    += -O0 -g
LOCAL_LDLIBS += -lX11

#ifeq ($(HOST_OS),windows)
#LOCAL_LDLIBS += -lws2_32 



 Fix 8 

Error:
external/llvm/include/llvm/ADT/PointerUnion.h:56:10: error: enumeral mismatch in conditional expression: ‘llvm::PointerLikeTypeTraits<llvm::PointerUnion<clang::Stmt*, const clang::Type*> >::<anonymous enum>’ vs ‘llvm::PointerLikeTypeTraits<clang::ObjCInterfaceDecl*>::<anonymous enum>’ [-Werror]
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs.o] Error 1


Fix:

vi frameworks/compile/slang/Android.mk
Remove '-Werror' from line 22:
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter 



 Fix 9 

Error:
frameworks/base/libs/rs/rsFont.cpp:224:76:   required from here
frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<unsigned int, android::renderscript::Font::CachedGlyphInfo*>’ are not found by unqualified lookup

frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead

make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o] Error 1

Fix:

vi frameworks/base/libs/rs/Android.mk
Add '-fpermissive' to line  183
LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive



Fix 10

Error:
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token
......
external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not declared in this scope
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1


Fix:

vi external/mesa3d/src/glsl/linker.cpp
Add '#include <stddef.h>' to list of includes as shown: 
#include <climits>
#include <stddef.h>
#include <pixelflinger2/pixelflinger2_interface.h>


Fix 11

Error:
external/gtest/src/../include/gtest/gtest-param-test.h:287:58: note: ‘template<class Container> testing::internal::ParamGenerator<typename Container::value_type> testing::ValuesIn(const Container&)’ declared here, later in the translation unit
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1


Two fixes required:
1)

vi external/gtest/src/Android.mk
Add '-fpermissive' to lines 52 and 70 (both lines contain same info)
LOCAL_CFLAGS += -O0 -fpermissive


2)

vi external/gtest/include/gtest/internal/gtest-param-util.h
Add '#include <stddef.h>' to list of includes as shown:
#include <vector>
#include <cstddef>
#include <gtest/internal/gtest-port.h>

Fix 12

Error:

host Executable: test-librsloader (out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader)
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a (Signals.o):在函数‘PrintStackTrace’中:
/home/crow/works/Android_src/external/llvm/lib/Support/Unix/Signals.inc:219:对‘dladdr’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Unix/Signals.inc:231:对‘dladdr’未定义的引用
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a (Threading.o):在函数‘llvm::llvm_execute_on_thread (void (*)(void*), void*, unsigned int)’中:
/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:96:对‘pthread_create’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:100:对‘pthread_join’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:91:对‘pthread_attr_setstacksize’未定义的引用
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a (Mutex.o):在函数‘llvm::sys::MutexImpl::MutexImpl (bool)’中:
/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:69:对‘pthread_mutexattr_init’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:75:对‘pthread_mutexattr_settype’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:80:对‘pthread_mutexattr_setpshared’未定义的引用
/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:89:对‘pthread_mutexattr_destroy’未定义的引用
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a (Mutex.o):在函数‘llvm::sys::MutexImpl::tryacquire ()’中:
/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:143:对‘pthread_mutex_trylock’未定义的引用
collect2: 错误: ld 返回 1
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] 错误 1

Fix:

$vi external/llvm/llvm-host-build.mk

末尾加上:

LOCAL_LDLIBS := -lpthread -ldl

编译 sdk 时遇到不少的问题

build/core/main.mk:670: *** Module 'AlarmProvider' in PRODUCT_PACKAGES has nothing to install!。

Indeed there is no a module with name AlarmProvider in the source tree now.
To fix it, remove AlarmProvider from the product definition in the following files:
./build/target/product/large_emu_hw.mk:25:    AlarmProvider
./build/target/product/generic_no_telephony.mk:24:    AlarmProvider

只去掉 generic_no_telephony.mk 就可以过,但是不过的东西太多了。
我想是 main.mk 中的判断方法有误,因为同样一个文件,编译镜像就可以过,编译 sdk 就过不了。

在编译源代码的时候出现该错误

/usr/bin/ld.bfd.real: cannot find -lGL

/usr/bin/ld.bfd.real: cannot find -lX11

根据网上大多数的说法,以及官网的介绍。截至 5 月底,android 对 ubuntu12.04 的编译平台的支持不是很推荐,有些库的兼容方面会有一些问题

这两个错误报的错其实就是说没有在库路径中找到 libGL.so libX11.so

但是打开 etc/ld.so.conf.d 中查看 64 位的库路径下 x86_64-linux-gnu.conf 配置文件

# Multiarch support
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

该路径下是有 libGL.so 的,并且查看文件链接指向没有问题。但是编译起来还是有错。

后来再查看了一些资料,因为编译的时候还是用到了 32BIT 的 libGL.so libX11.so 库文件,编译的时候找的不是 X86_64 库文件配置,而是找的是 I386 库文件配置

# Multiarch support
/lib/i386-linux-gnu
/usr/lib/i386-linux-gnu
/lib/i686-linux-gnu
/usr/lib/i686-linux-gnu

果然在 I386 目录下没有找到这两个文件

首先安装这两个库文件的 32 位版本:

$ sudo apt-get install libx11-dev:i386(libX11.so)
$ sudo apt-get installibgl1-mesa-glx:i386(libGL.so)

由于 libGL.so 系统默认没有进行库路径下的链接,还需要手动链接一下

$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1.2 /usr/lib/libGL.so

查找指定的符号在 Android.mk 中

find ./ -name Android.mk -exec grep -l {} \;

环境要求改变。

    现在要求内存 1.5G 左右,硬盘 25G 以上,以前 1G、10G 就够了。官方说明 “Note: The source download is approximately 6GB in size. You will need 25GB free to complete a single build, and up to 80GB (or more) for a full set of builds.”

     可惜我编之前没看,编译报错如下:   

错一:

host SharedLib: libbcc (out/host/linux-x86/obj/lib/libbcc.so)

collect2: ld terminated with signal 9 [Killed]

make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex] Killed

make: *** Waiting for unfinished jobs….

make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/llvm-rs-cc] Error 1

collect2: ld terminated with signal 9 [Killed]

collect2: ld terminated with signal 9 [Killed]

make: *** [out/host/linux-x86/obj/lib/libbcc.so] Error 1

make: *** [out/host/linux-x86/obj/EXECUTABLES/clang_intermediates/clang] Error 1

weihongcsu@ubuntu:~/disk2/android-4.0.1_r1$

错二:

target Dex: framework

make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex] Killed

sunxu@ubuntu:~/disk2/android-4.0.1_r1$

错三:

arm-eabi-g++: Internal error: Killed (program cc1plus)

解决办法:

这些错误都是 linux 的 OOM killer 导致,“内存 1.5G 左右,硬盘 25G” 就可以解决,我为了保险,把 make -j4 改成了 make. 编译 5 个小时以上吧,out 目录大小:12G。


参考:
1.http://blog.csdn.net/mr_raptor/article/details/7394091
2.https://groups.google.com/forum/#!topic/android-building/kbhPdb6osms

收集和遇到的部分 error,先记录如下,改天按照建立 android 及使用情景分类整理。以后遇到的在慢慢添加进来

1. 编译错误:

“/usr/bin/ld:cannotfind -lz”

解决方法:

需要安装 zlib-dev 这个包,在线安装命令为:

apt-getinstall zlib1g-dev

2. 编译错误:

frameworks/base/libs/utils/RefBase.cpp:483:67:error: passing ‘const android::RefBase::weakref_impl’ as ‘this’argument of ‘void android::RefBase::weakref_impl::trackMe(bool,bool)’ discards qualifiers [-fpermissive]
make: ***[out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o]Error 1

解决方法:

$gedit frameworks/base/libs/utils/Android.mk

修改以下语句

LOCAL_CFLAGS+= -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

LOCAL_CFLAGS+= -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive

3. 编译错误:

arm-eabi-gcc:error trying to exec 'cc1': execvp: No such file or directory
make:*** [out/target/product/generic/obj/lib/crtbegin_dynamic.o] Error 1

解决方法:

如果之前的依赖包都已经安装成功的话,此处应该是交叉编译工具权限的问题。这个问题只要在文章开头 lunch 时执行了赋予权限命令,就应该不会遇到了。

4. 编译错误:

<command-line>:0:0:error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>:0:0: note: this is the location of the previousdefinition
cc1plus: all warnings being treated as errors
make:*** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]Error 1

此处编译错误是由于 ubuntu11.10 采用了 GCC4.6.1 导致的。

解决方法:

修改源码目录下 /build/core/combo/HOST_linux-x86.mk 文件:

将以下语句

HOST_GLOBAL_CFLAGS+= -D_FORTIFY_SOURCE=0

修改为

HOST_GLOBAL_CFLAGS+= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

5. 编译错误:

make:***[out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs_export_foreach.o] 错误 1

解决办法:

找到 frameworks/compile/slang/slang_rs_export_foreach.cpp: 的 249 行,即:

llvm::StringRef ParamName = PVD->getName();

将本行注释掉即可继续编译。

make:*** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]Error 1

后来发现了,原来是 Ubuntu11.10 里的 gcc 和 g++ 版本太高了,于是执行下面的操作:

sudoapt-get install gcc-4.4

sudoapt-get install g++-4.4

sudorm -rf /usr/bin/gcc /usr/bin/g++

sudoln -s /usr/bin/gcc-4.4 /usr/bin/gcc

sudoln -s /usr/bin/g++-4.4 /usr/bin/g++

把默认的 4.6 版本换为了 4.4,继续编译源码,又出现了另一个错误,大致提示为:

g++selected multilib '32' not installed

继续奋战吧,安装相应的工具吧:

sudo apt-get install g++-4.4-multilib

,现在正在 make-j8 在我的 i5/4G 机子里跑着。

make:***[out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o]Error 1

解决这个问题需要修改文件如下:

把 "#include<stddef.h>" 添加到 linker.cpp 文件头部。

这样就可以编译完成了。

6. 错误:

error:‘ptrdiff_t’ does not name a type
In file included fromexternal/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                from external/gtest/src/../include/gtest/gtest.h:69,
                fromexternal/gtest/src/gtest_main.cc:32:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11:error: ‘ptrdiff_t’ does not name a type
In file included fromexternal/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                from external/gtest/src/../include/gtest/gtest.h:69,
                from external/gtest/src/../src/gtest.cc:34,
                fromexternal/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11:error: ‘ptrdiff_t’ does not name a type
In file included fromexternal/gtest/src/gtest-all.cc:38:0:

解决方法:
 

$vi external/gtest/src/../include/gtest/internal/gtest-param-util.h
#include<cstddef>


7. 错误:

undefinedreference to `pthread_mutexattr_destroy'
host C++: libgtest_host<= external/gtest/src/gtest-all.cc
true
host C++:libgtest_main_host <=external/gtest/src/gtest_main.cc
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Signals.o):In function`PrintStackTrace':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Unix/Signals.inc:219:undefined reference to`dladdr'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Unix/Signals.inc:231:undefined reference to`dladdr'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Threading.o):In function `llvm::llvm_execute_on_thread(void (*)(void*), void*,unsignedint)':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:96:undefined reference to`pthread_create'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:91:undefined reference to`pthread_attr_setstacksize'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:100:undefined reference to`pthread_join'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o):In function`MutexImpl':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:69:undefined reference to`pthread_mutexattr_init'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:75:undefined reference to`pthread_mutexattr_settype'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:80:undefined reference to`pthread_mutexattr_setpshared'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:89:undefined reference to`pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o):In function`llvm::sys::MutexImpl::tryacquire()':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:143:undefined reference to `pthread_mutex_trylock'
collect2: ldreturned 1 exit status
make: ***[out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader]Error 1
make: *** Waiting for unfinished jobs....

解决方法:

$vi external/llvm/llvm-host-build.mk
LOCAL_LDLIBS := -lpthread-ldl


下面这个解决方法没成功,会有新的错误:errorsagain :can't find threads.h file or dir.
 

$ vi external/llvm/lib/Support/Android.mk
LOCAL_C_INCLUDES +=system/core/include/cutils
LOCAL_SHARED_LIBRARIES := libcutil
$vi external/llvm/lib/Support/Mutex.cpp
#include <threads.h>
$vi external/llvm/lib/Support/Threading.cpp
#include<threads.h>


8 错误:

error:variable ‘ParamName’ set but not used[-Werror=unused-but-set-variable]
frameworks/compile/slang/slang_rs_export_foreach.cpp:247:23:error: variable ‘ParamName’ set but not used[-Werror=unused-but-set-variable]
cc1plus: all warnings beingtreated as errors


解决方法:

$vi frameworks/compile/slang/Android.mk 
#local_cflags_for_slang :=-Wno-sign-promo -Wall -Wno-unused-parameter-Werror
local_cflags_for_slang := -Wno-sign-promo -Wall-Wno-unused-parameter

9. 错误:

一、环境设置

在 lunch 时,如果提示 permissiondenied 权限不够的话,需要在源码根目录下执行,赋予目录下所有文件权限

sunxu@sunxu:~/Android/source$sudo chmod -R 777 *

这时候会 lunch 指令会打印出如下所示文段:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.3
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRI40
============================================

一、开始编译

编译过程可能会出现许多错误而中止,在此 wayne 将会把所有遇到的问题以及解决方法一一贴出来,以供以后参考。

10. 错误:

sunxu@sunxu::~/Android/source$make-j2
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.3
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRI40
============================================
Checkingbuild tools versions...
build/core/main.mk:76:************************************************************
build/core/main.mk:77:You are attempting to build on a 32-bitsystem.
build/core/main.mk:78: Only 64-bit build environments aresupported beyond froyo/2.2.
build/core/main.mk:79:************************************************************
build/core/main.mk:80:*** stop。停止。

解决方法:cd 到源码根目录,执行:

$gedit build/core/main.mk

找到

ifneq(64,$(findstring 64,$(build_arch)))

将其修改为

ifneq(i686,$(findstring i686,$(build_arch)))

然后依次修改以下四个 make 文件:

external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk

将其中的

LOCAL_CFLAGS+= -m64
LOCAL_LDFLAGS += -m64

修改为

LOCAL_CFLAGS+= -m32
LOCAL_LDFLAGS += -m32

11. 错误:

frameworks/base/libs/utils/RefBase.cpp:483:67:error: passing ‘const android::RefBase::weakref_impl’ as ‘this’argument of ‘void android::RefBase::weakref_impl::trackMe(bool,bool)’ discards qualifiers [-fpermissive]
make: ***[out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o]Error 1

解决方法:

$gedit frameworks/base/libs/utils/Android.mk

修改以下语句

LOCAL_CFLAGS+= -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

LOCAL_CFLAGS+= -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive

12. 错误:

arm-eabi-gcc:error trying to exec 'cc1': execvp: No such file or directory
make:*** [out/target/product/generic/obj/lib/crtbegin_dynamic.o] Error 1

如果之前的依赖包都已经安装成功的话,此处应该是交叉编译工具权限的问题。这个问题只要在文章开头 lunch 时执行了赋予权限命令,就应该不会遇到了。

13. 错误:

<command-line>:0:0:error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>:0:0: note: this is the location of the previousdefinition
cc1plus: all warnings being treated as errors
make:*** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]Error 1

此处编译错误是由于 ubuntu11.10 采用了 GCC4.6.1 导致的。

解决方法:

修改源码目录下 /build/core/combo/HOST_linux-x86.mk 文件:

将以下语句

HOST_GLOBAL_CFLAGS+= -D_FORTIFY_SOURCE=0

修改为

HOST_GLOBAL_CFLAGS+= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

编译时还有可能出现类似的错误,根据错误提示的关键词比如 g++ 错误、jre 错误等,都是些细节问题,比较好解决。

经过两小时左右的等待后,终于顺利完成。编译成功后会生成 system.img 等镜像文件,下面是编译完成提示:

Targetsystem fs image:out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Installsystem fs image: out/target/product/generic/system.img
Installedfile list: out/target/product/generic/installed-files.txt

三、启动所编译的系统

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

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

gedit~/.bashrc

,新增环境变量如下:

exportANDROID_PRODUCT_OUT=~/Android/source/out/target/product/generic
ANDROID_PRODUCT_OUT_BIN=~/Android/source/out/host/linux-x86/bin
exportPATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};

最后,同步这些变化并启动模拟器:

$source ~/.bashrc
$ cd~/Android/source/out/target/product/generic
$ emulator -systemsystem.img -data userdata.img -ramdisk ramdisk.img

加载上我们所编译出来的系统文件,终于出现了期待已久的模拟器:

ubuntu 编译 Android 出现的若干错误及解决方法

刚下好 android 源码后马上编译会发现有各种各样的错误,原因是有些依赖包没有装。

为了避免出现以下我遇到的错误,请先安装 jdk1.5,必须是 jdk1.5,不然肯定编译不过的。

然后,在检查以下有没有安装以下依赖包:

sudo apt-get install bison libc6-dev-amd64 g++-multilib zlib1g-devlib64z1-dev flex libncurses5-dev libx11-dev gperf

下面是我遇到的错误及解决方法:

/bin/bash:bison:找不到命令
Checkingbuild toolsversions...
************************************************************
Youare attempting to build with the incorrect version
of java.

Yourversion is: /bin/bash: java:找不到命令.
Thecorrect version is: 1.6.

Pleasefollow the machine setup instructions at

http://source.android.com/source/download.html

************************************************************
build/core/main.mk:114:*** stop

解决方法:

sudo apt-get install bison

错误:

hostSharedLib: libneo_util(out/host/linux-x86/obj/lib/libneo_util.so)
/usr/bin/ld: skippingincompatible /usr/lib/gcc/i486-linux-gnu/4.4.3/libstdc++.so whensearching for -lstdc++
/usr/bin/ld: skipping incompatible/usr/lib/gcc/i486-linux-gnu/4.4.3/libstdc++.a when searching for-lstdc++
/usr/bin/ld: skipping incompatible/usr/lib/gcc/i486-linux-gnu/4.4.3/libstdc++.so when searching for-lstdc++
/usr/bin/ld: skipping incompatible/usr/lib/gcc/i486-linux-gnu/4.4.3/libstdc++.a when searching for-lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ldreturned 1 exit status
make: ***[out/host/linux-x86/obj/lib/libneo_util.so] 错误 1

解决方法:

sudoapt-get install g++-multilib

external/clearsilver/cgi/cgi.c:22:18:error: zlib.h: 没有那个文件或目录
external/clearsilver/cgi/cgi.c:In function ‘cgi_compress’:
external/clearsilver/cgi/cgi.c:885:error: ‘z_stream’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:885: error: (Eachundeclared identifier is reported onlyonce
external/clearsilver/cgi/cgi.c:885: error: for each functionit appears in.)
external/clearsilver/cgi/cgi.c:885: error:expected ‘;’ before ‘stream’
external/clearsilver/cgi/cgi.c:888:error: ‘stream’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:888: error: ‘Bytef’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:888: error: expectedexpression before ‘)’ token
external/clearsilver/cgi/cgi.c:889:error: ‘uInt’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:889: error: expected ‘;’before ‘str’
external/clearsilver/cgi/cgi.c:890: error:expected expression before ‘)’token
external/clearsilver/cgi/cgi.c:892: error: ‘uLong’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:892: error: expected ‘)’before ‘stream’
external/clearsilver/cgi/cgi.c:895: error:‘alloc_func’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:895: error: expected ‘;’before numeric constant
external/clearsilver/cgi/cgi.c:896: error:‘free_func’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:896: error: expected ‘;’before numeric constant
external/clearsilver/cgi/cgi.c:897: error:‘voidpf’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:897: error: expected ‘;’before numeric constant
external/clearsilver/cgi/cgi.c:900: error:‘Z_DEFAULT_COMPRESSION’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:900: error: ‘Z_DEFLATED’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:900: error: ‘MAX_WBITS’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:900: error:‘Z_DEFAULT_STRATEGY’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:901: error: ‘Z_OK’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:904: error: ‘Z_FINISH’undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:905: error:‘Z_STREAM_END’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c: In function‘cgi_output’:
external/clearsilver/cgi/cgi.c:1200: error:‘Z_NULL’ undeclared (first use in thisfunction)
external/clearsilver/cgi/cgi.c:1201: error: expected ‘)’before ‘Bytef’
external/clearsilver/cgi/cgi.c:1201: warning:cast from pointer to integer of differentsize
external/clearsilver/cgi/cgi.c:1218: error: ‘Z_DEFLATED’undeclared (first use in this function)
make: ***[out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_cgi_intermediates/cgi.o] 错误 1

解决方法:

sudo apt-get install zlib1g-dev

hostSharedLib: libneo_cgi(out/host/linux-x86/obj/lib/libneo_cgi.so)
/usr/bin/ld: skippingincompatible /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../libz.so whensearching for -lz
/usr/bin/ld: skipping incompatible/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../libz.a when searching for-lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.so whensearching 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/lib/libneo_cgi.so] 错误 1

解决方法:

sudo apt-get install lib64z1-dev

out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:In function ‘intyyparse()’:
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:找不到命令
make:***[out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] 错误 127

解决方法:

sudo apt-get install flex

Docsdroiddoc: out/target/common/docs/api-stubs
Could not load'clearsilver-jni'
java.library.path = out/host/linux-x86/lib
make:*** [out/target/common/docs/api-stubs-timestamp] 错误 45

解决方法:
安装 jdk1.5

hostExecutable: 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] 错误 1

解决方法:

sudo apt-get install libncurses5-dev

hostC: emulator <= external/qemu/android/main.c
In file includedfromexternal/qemu/android/main.c:30:
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:55:22:error: X11/Xlib.h: 没有那个文件或目录
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:56:23:error: X11/Xatom.h: 没有那个文件或目录
Infile included fromexternal/qemu/android/main.c:30:
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:73:error: expected specifier-qualifier-list before‘XEvent’
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:86:error: expected specifier-qualifier-list before‘Display’
external/qemu/android/main.c: In function‘main’:
external/qemu/android/main.c:1281: warning: implicitdeclaration of function ‘audio_check_backend_name’
make: ***[out/host/linux-x86/obj/EXECUTABLES/emulator_intermediates/android/main.o] 错误 1

解决方法:

sudo apt-get install libx11-dev

GeneratingCSSPropertyNames.h <= CSSPropertyNames.in
sh: gperf: notfound
calling gperf failed: 32512 at ./makeprop.pl line 96.
make:***[out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/WebCore/css/CSSPropertyNames.h] 错误 25
make:*** 正在删除文件 “out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/WebCore/css/CSSPropertyNames.h”

解决方法:

sudo apt-get install gperf

host Java: jsr305lib (out/host/common/obj/JAVA_LIBRARIES/jsr305lib_intermediates/classes)
/bin/bash: jar: command not found
make: *** [out/host/common/obj/JAVA_LIBRARIES/jsr305lib_intermediates/javalib.jar] Error 127


fix:
cd /usr/bin
必须先进入 /usr/bin,下同
sudo ln -s -f /usr/lib/jvm/jdk1.6.0_30/bin/jar
我的 jdk 是安装在 /usr/lib/jvm/jdk1.6.0_30 / 目录下的
如果提示 javah:commond not found,于是照葫芦画瓢,输入命令
cd /usr/bin
ln -s -f /usr/lib/jvm/jdk1.6.0_30/bin/javah


frameworks/base/tools/obbtool/Main.cpp:1:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1


fix:
将以下语句 (line56)

HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0

修改为

HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1

external/gtest/include/gtest/internal/gtest-param-util.h
add
#include <cstddef>

错误
Fetching projects: 100% (294/294), done.  
Traceback (most recent call last):
  File "/home/helei/workspace/android_source/.repo/repo/main.py", line 385, in <module>
    _Main(sys.argv[1:])
  File "/home/helei/workspace/android_source/.repo/repo/main.py", line 365, in _Main
    result = repo._Run(argv) or 0
  File "/home/helei/workspace/android_source/.repo/repo/main.py", line 137, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/helei/workspace/android_source/.repo/repo/subcmds/sync.py", line 469, in Execute
    project.Sync_LocalHalf(syncbuf)
  File "/home/helei/workspace/android_source/.repo/repo/project.py", line 1049, in Sync_LocalHalf
    lost = self._revlist(not_rev(revid), HEAD)
  File "/home/helei/workspace/android_source/.repo/repo/project.py", line 1791, in _revlist
    return self.work_git.rev_list(*a, **kw)
  File "/home/helei/workspace/android_source/.repo/repo/project.py", line 1936, in rev_list
    p.stderr))
error.GitError: platform/abi/cpp rev-list ('^e9832499ad6834be10fd651b80871630ca7206c6', 'HEAD', '--'): fatal: bad object e9832499ad6834be10fd651b80871630ca7206c6


解决办法是:删除以前生成的所有源码目录,注意除.repo 以外,这个目录中包含你从源码树上同步下来的所有源码,之前删除的文件只是源码树中由脚本自动提取的对应分支的源码。

make: *** [out/target/common/obj/APPS/Calculator_intermediates/classes-full-debug.jar] 错误 41
make: *** 正在等待未完成的任务....
packages/apps/Camera/src/com/android/camera/BitmapManager.java:19: 无法访问 android.content.ContentResolver
错误的类文件: android/content/ContentResolver.class (android/content:ContentResolver.class)
无法访问文件: corrupted zip file
请删除该文件或确保该文件位于正确的类路径子目录中。
import android.content.ContentResolver;
                      ^
make: *** [out/target/common/obj/APPS/Camera_intermediates/classes-full-debug.jar] 错误 41
development/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.java:19: 无法访问 android.view.animation.Animation
错误的类文件: android/view/animation/Animation.class (android/view/animation:Animation.class)
无法访问文件: corrupted zip file
请删除该文件或确保该文件位于正确的类路径子目录中。
import android.view.animation.Animation;
                             ^
make: *** [out/target/common/obj/APPS/ApiDemos_intermediates/classes-full-debug.jar] 错误 41
packages/apps/DeskClock/src/com/android/alarmclock/AnalogAppWidgetProvider.java:22: 无法访问 android.app.PendingIntent
错误的类文件: android/app/PendingIntent.class (android/app:PendingIntent.class)
无法访问文件: corrupted zip file
请删除该文件或确保该文件位于正确的类路径子目录中。
import android.app.PendingIntent;
                  ^
make: *** [out/target/common/obj/APPS/DeskClock_intermediates/classes-full-debug.jar] 错误 41


解决方法

以上错误是由于编译系统文件时没安装所需要包,以下是整个过程中所需的所有包:

$sudo apt-get install git-core gnupg gperf libsdl-dev libesd0-dev

$sudo apt-get install libwxgtk2.6-dev zip curl minicom tftpd

$sudo apt-get install uboot-mkimage libx11-dev libncurses-dev

$sudo apt-get install expect bison build-essential flex zlib1g-dev
<span style="font-size: 18px;">之后输入如下命令来清除已编译的:$ make clobber</span>

接着重新编译就可以了

本文含有隐藏内容,请 开通VIP 后查看