1. 程式人生 > >Mac OS X下搭建Android Source編譯環境的問題及解決方法

Mac OS X下搭建Android Source編譯環境的問題及解決方法

[轉發請註明出處,謝謝]

本文的編譯環境指的是Android KernelFramework的編譯,不是Application的開發環境

有詳細說明的只給出連結和要點提示。

大的步驟就是Androidsource網站的原文

“Initializing a Build Environment”Setting up a Mac OS X build environment部分。

要點提示:

1. 建立case-sensitive disk image.的問題

原文提到要在~/.bash_profile檔案新增mountAndroid命令。好多人找不到此檔案。

其實,預設Mac OS X

是沒有這個檔案的。可以參考下文解決

也就是要自己產生此檔案,並且編輯加入內容,編輯好儲存後要執行

source .bash_profile

來更新配置。

2.Xcode的問題

Android官方推薦裝Xcode3.1.4版本但是先在都4.x了,其實主要是要MacOS SDK 10.5.

請參考連結:

連結:http://blog.csdn.net/dragon1225/article/details/7061076

[註釋:連結文章提到編譯時strnlen的錯誤問題,這個將下文列舉]

2)10.5的SDK包可以通過這裡下載

http://blog.csdn.net/guoguoljg/article/details/7300940

3.通過Macport裝相關的包的過程中遇到的問題

1Python27安裝錯誤,解決方案:自己重新找源安裝即可;

2xz錯誤(好像和Python有關係):自己手動裝xz sudo port install xz

4.編譯Android遇到的問題

1)問題error: elf.h: No such file or directory

原因:Mac缺少elf.h檔案

解決方法:參考這裡http://blog.csdn.net/quaful/article/details/6053708

思想:從網上下個elf標頭檔案,放到scripts/mod/資料夾裡,要修改兩個檔案mk_elfconfig.c

modpost.h

#include <elf.h>改為#include "elf.h"

2)問題error: static declaration of ‘strnlen’ follows non-static declaration

/usr/include/string.h:143: error: previous declaration of ‘strnlen’ was here

原因:通過解決方案發現這個strnlen時多餘的

解決:方案一,替換這個函式, 參考http://dyf128.iteye.com/blog/1258943

方案二,函式外圍加巨集或者註釋掉,參考

我採用方案二,參考

#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070 
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
	int len = 0;
	while (__maxlen-- && *__string++)
		len++;
	return len;
}
#endif

無論哪個方案都會引來下面的新問題。

(3)問題 warning: ignoring file out/host/darwin-x86/obj/STATIC_LIBRARIES/ 
libSDL_intermediates/libSDL.a, file was built for archive which is not 
the architecture being linked (i386) 
Undefined symbols for architecture i386

原因:不明

解決:註釋掉Android.mk的所有內容

參考:

# the following test is made to detect that we were called
# through the 'm' or 'mm' build commands. if not, we use the
# standard QEMU Makefile
#
###################Comment by Damon on June 28, 2012###########################
#ifeq ($(DEFAULT_GOAL),droid)
#    LOCAL_PATH:= $(call my-dir)
#    include $(LOCAL_PATH)/Makefile.android
#else
#    include Makefile.qemu
#endif
##############################################################

相關參考

i) http://dyf128.iteye.com/blog/1258943

ii) http://groups.google.com/group/android-building/browse_thread/thread/bd566c8b513a4946

iii) http://www.linuxidc.com/Linux/2012-06/61754.htm