Android 编译错误总结及收集

时间:2022-11-28 05:28:31

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


1.编译错误:

/usr/bin/ldcannotfind -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:247行,并将本行注释掉即可继续编译。

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

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

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

继续奋战吧,安装相应的工具吧:sudoapt-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:
解决方法:
$viexternal/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....
解决方法:
$viexternal/llvm/llvm-host-build.mk
LOCAL_LDLIBS := -lpthread-ldl
下面这个解决方法没成功,会有新的错误:errorsagain :can't find threads.h file or dir.
$ viexternal/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.错误:

一、环境设置

wayne@wayne-pc:~/Android/source$source build/envsetup.sh
includingdevice/htc/passion/vendorsetup.sh
includingdevice/samsung/crespo/vendorsetup.sh
wayne@wayne-pc:~/Android/source$lunch full-eng

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

wayne@wayne-pc:~/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.错误:

wayne@wayne-pc:~/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,不然肯定编译不过的。

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

sudoapt-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
。停止。

解决方法:
sudoapt-get install bison

Install:out/host/linux-x86/framework/droiddoc.jar
target Generated:libclearsilver-jni <=out/host/common/obj/JAVA_LIBRARIES/clearsilver_intermediates/javalib.jar
hostC: libclearsilver-jni <=external/clearsilver/java-jni/j_neo_util.c
In file included from/usr/include/features.h:378,
from /usr/include/string.h:26,
fromexternal/clearsilver/java-jni/j_neo_util.c:1:
/usr/include/gnu/stubs.h:9:27:error: gnu/stubs-64.h:
没有那个文件或目录
make:***[out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o]
错误1

解决方法:
sudoapt-get install libc6-dev-amd64

http://www.poemcode.net/2010/07/android-stubs-64/

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

解决方法:
sudoapt-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

解决方法:
sudoapt-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

解决方法:
sudoapt-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

解决方法:
sudoapt-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

解决方法:
sudoapt-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”

解决方法:
sudoapt-get install gperf