写在最前:用虚拟机装ubuntu,还下载android源码并且编译的,上辈子都是折翼的天使!!
为了编译的更加流畅,强烈要求虚拟机内存要至少1G、任务管理器中虚拟机进程优先级设置为实时。
4、源码编译镜像文件
开始正式编译,在源码目录下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
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
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
In the gingerbread branch of AOSP, on Ubuntu 11.10 x86_64 running Linux 3.0.0-12-generic, builds fail on obbtool (frameworks/base/tools/obbtool/Main.cpp) with: error: "_FORTIFY_SOURCE" redefined [-Werror] Interestingly, the same build worked on Ubuntu 11.04 x86_64 -- the source tree was restored with rsync -av after a fresh install of Ubuntu 11.10 beta1 (which today has the latest OS packages). I am unable to see if the HEAD of the branch has fixed the issue as the origin git host is down. The fix is to apply a patch from Jim Huang (jserv) found on CyanogenMod's android_build from Sep 6, 2011. Simply change build/core/combo/HOST_linux-x86.mk line 61: -HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0 +HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 His commit message is as follows: HOST_linux-x86: Avoid doubly define macro _FORTIFY_SOURCE While building Android with latest host gcc, it causes the following build error: Install: out/host/linux-x86/bin/mkbootimg host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp <command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] <built-in>:0:0: note: this is the location of the previous definition cc1plus: all warnings being treated as errors In order to make build system happy, this patch does unset macro _FORTIFY_SOURCE and then define it in host cflags. https://github.com/CyanogenMod/android_build/commit/e9cbfa60c8dd60d04570d8bf7bd0d54a4304baf5 Here's how I initiated the build, in the AOSP gingerbread branch: . build/envsetup.sh lunch full_crespo-eng make droid The problem appears to be related to gcc, so here's the output of `gcc -v`: Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.1-9ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) The discussion here might be related: http://groups.google.com/group/android-building/browse_thread/thread/f2a2abcb8aeb1ecb/48668dacd0cd0ff8
5、编译SDK
执行$sudo make PRODUCT-sdk-sdk命令,生成对应于该版本源代码的用于生产环境的sdk。
编译的SDK版本,实际位置是./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86。
因为它比较常用,我们给它高优先级:
update-alternatives --install /usr/bin/AndroidSDK AndroidSDK ./out/host/linux-x86/sdk/android-sdk_eng.root_linux-x86 255
然后使用update-alternatives --display AndroidSDK查看当前配置情况;
如果要切换配置,使用update-alternatives --config AndroidSDK。
配置AndroidSDK环境变量。终端中执行gedit ~/.bashrc
在文件最后添加下面三行:
# set android environment
export ANDROID_SDK_HOME=/usr/bin/AndroidSDK
export PATH=$ANDROID_SDK_HOME/tools:$PATH
保存文件。在终端中执行source ~/.bashrc
最近又编译了一次2.2sdk,但是在编译doc时,提示空指针,怎么都搞不定,求解。
最后使用的是jdk1.6编译的2.3的源码。
6、在模拟器中运行编译的镜像
打开终端,执行android脚本:
$android
选择左边第一项Virtual Devices,然后在右边选择New,新建一个AVD。
Name:AVD的名称,随便取,但只能包含字母和数字以及点、下划线和连字符,这里取名test。
Traget:目标SDK版本,这里选自己编译的2.2版Android SDK。
SD Card:SD卡。暂且不填,待需要时再设置。
Skin:皮肤(模拟器屏幕分辨率)。
Hardware:使用默认即可
然后点Create AVD,就创建好了一个AVD。点击Start即
可启动模拟器,其运行的是自己编译的镜像。