Ubuntu11.10(32位)编译android常见错误
开始正式编译,在源码目录下make即可。
make
我完全不知道跑了个啥,只知道超级卡。完成后产生的out文件夹有3.9G。
镜像生成在out/target/product/generic下:android源码编译后得到system.img,ramdisk.img,userdata.img映像文件。其中, ramdisk.img是emulator的文件系统,system.img包括了主要的包、库等文件,userdata.img包括了一些用户数据,emulator加载这3个映像文件后,会把 system和 userdata分别加载到 ramdisk文件系统中的system和 userdata目录下。
当然编译是件很痛苦的事情:
错误1:
************************************************************
You are attempting to build on a 32-bit system.
Only 64-bit build environments are supported beyond froyo/2.2.
************************************************************
解决:
需要进行如下修改即可,将
./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
注释掉,或者将“64”换成“32”
LOCAL_CFLAGS += -m32
LOCAL_LDFLAGS += -m32
然后,将./build/core/main.mk 中的
ifneq (64,$(findstring 64,$(build_arch)))
改为:
ifneq (i686,$(findstring i686,$(build_arch)))
错误2:
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
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] 错误 1
解决:
gedit frameworks/base/libs/utils/Android.mk
Change the line:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
To:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
错误3:
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] 错误 1
解决:
打开 frameworks/base/tools/aapt/Android.mk
然后打开文件Android.mk,编辑下面一行:
ifeq ($(HOST_OS),linux)
#LOCAL_LDLIBS += -lrt 把这行注释掉,改为下面一行。
LOCAL_LDLIBS += -lrt -lpthread
endif
错误4:
target Dex: core
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0x4003d848, pid=7668, tid=2889534320
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_22-b03 mixed mode)
# Problematic frame:
# C [libpthread.so.0+0xa848] pthread_cond_timedwait+0x168
#
# An error report file with more information is saved as hs_err_pid7668.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.dex] 已放弃 (core dumped)
解决:
虚拟机给的内存512太小,给个1G试试。然后在本机里打开任务管理器,找到虚拟机进程,优先级设置为实时。给他最多东西。
错误 5:
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
/home/leno/works/android_dev/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize] 错误 1
解决:类似问题3
修改./framework/base/tools/localize/Android.mk文件
ifeq ($(HOST_OS),linux)
#LOCAL_LDLIBS += -lrt 把这行注释掉,改为下面一行。
LOCAL_LDLIBS += -lrt -lpthread
endif
错误1:
注意:external/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java 使用了未经检查或不安全的操作。
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libhost_intermediates/pseudolocalize.o] 错误 1
注意:要了解详细信息,请使用 -Xlint:unchecked 重新编译。
解决方法:sudo apt-get install libc6-dev-i386
http://www.blogjava.net/ZircoN/archive/2011/11/13/363452.html
错误2:
frameworks/base/libs/utils/ResourceTypes.cpp:4375:43: 警告: 将一个整数转换为大小不同的指针 [-Wint-to-pointer-cast]
参考网上的解决方法:$ gedit frameworks/base/libs/utils/Android.mk
将下面一行
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
改成
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) –fpermissive
http://www.blogjava.net/ZircoN/archive/2011/11/13/363452.html
问题并没有解决,反而又出现了新的错误:
host C++: libutils <= frameworks/base/libs/utils/Asset.cppmake: *** 正在等待未完成的任务....
这个错误主要是gcc版本过高引起的:最终解决办法是:
http://hi.baidu.com/designhouse/blog/item/fec5cdbf8d6a231618d81fc1.html)
ubuntu 11.10的gcc版本是4.6.1,版本太高,编译android时出错,要把gcc版本改为4.4.3。
通过gcc -v命令可以发现gcc库在/usr/lib/gcc/i686-linux-gnu目录下,该目录下有当前系统支持的各种版本gcc库 。在安装gcc 4.4前该目录下是没有4.4目录的,安装gcc 4.4后该目录下就会多出4.4这个目录,且该4.4目录下有各种相应库文件。
ubuntu 32bit系统下安装gcc 4.4的最好方法是仅用以下两条命令,不需要其它命令,否则编译时可能会出错。
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
$ ls -l gcc*
lrwxrwxrwx 1 root root 7 2011-10-29 09:11 gcc -> gcc-4.6
-rwxr-xr-x 1 root root 224544 2011-10-06 05:47 gcc-4.4
-rwxr-xr-x 1 root root 302104 2011-09-17 05:43 gcc-4.6
发现gcc 链接到gcc-4.6, 需要将它改为链接到gcc-4.4 :sudo mv gcc gcc.bak
sudo ln -s gcc-4.4 gcc
$ls -l g++*
sudo -s
mv g++-4.4 g++
g++ -v
错误3:
解决方法:
输入:sudo apt-get install gcc-multilib
sudo apt-get install g++-multilib后出现新问题:
make: *** [out/host/linux-x86/obj/lib/libfst.so] 错误 1
解决方法
sudo apt-get install libc6-dev ia32-libs lib32ncurses5-dev x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z-dev libgl1-mesa-dev mingw32 tofrodos python-markdown libxml2-utils
sudo apt-get install g++-4.4-multilib
错误4:
解决方法:
这是由于clearsilver 在编译时如果检测到使用Java JDK 6,就使用64位编译。要避开此错误,需要修改下面四个文件:
* external/clearsilver/cgi/Android.mk
* external/clearsilver/java-jni/Android.mk
* external/clearsilver/util/Android.mk
* external/clearsilver/cs/Android.mk
把这四个Makefile中的下列语句注掉即可:
# This forces a 64-bit build for Java6
# Comment by Easwy
# LOCAL_CFLAGS += -m64
# LOCAL_LDFLAGS += -m64
然后在external/clearsilver目录中执行一下make clean,然后回到项目根目录,继续make即可。
当编译完成时,生成的image文件放在out/target/product/generic目录中。
gedit /root/.bashrc
export PATH=/root/android/mydroid/out/host/linux-x86/bin:$PATH
export ANDROID_PRODUCT_OUT=/root/android/mydroid/out/target/product/generic
export ANDROID_SWT=/root/android/mydroid/out/host/linux-x86/framework
在源码目录下的out/target/product/generic/目录下运行
emulator -image system.img -data userdata.img -ramdisk ramdisk.img 命令
错误5:
emulator
NAND: could not write file system.img, File exists