赖3881 发表于 2016-5-15 13:40:21

Mac OS X 下android源码编译

1.需要至少15G大的大小写敏感分区,以免build debug版本空间不够

在Mac下编译android的源代码需要一个大小写敏感(Case Sensitive)的分区格式如果你原来的分区不是HFS一类大小写敏感的文件格式,那么最简单的办法就是新建一个这种分区格式的dmg出来,命令如下:

sudo hdiutil create -size 15g -type UDIF -fs HFSX -volname android~/android.dmg
sudo chown $USER~/android.dmg

1)双击android.dmg,mount volume到/Volumes/android。

2)进入系统偏好设置-->帐户-->登录项-->点"+",选android.dmg这样系统启动的时候会自动mount volume

2.下载代码或者直接拷贝已有源代码到/Volumes/android目录下

下载源码需要安装Repo工具,该工具是为了更好的使用Git源代码管理软件(类似于CVS等版本控制系统),执行以下命令创建~/bin目录:

$ cd ~
$ mkdir bin
$ echo $PATH


下载Repo:

$ curl https://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo

之后在/Volumes/android目录下创建android目录以存放android源码:

$ cd /Volumes/android
$ mkdir android
$ cd android

接着初始化Repo客户端:

$ repo init -u git://android.git.kernel.org/platform/manifest.git

成功后显示:

repo initialized in /Volumes/android/android

这时在/Volumes/android/android目录下就会有.repo的目录用来同步manifest文件,该文件是用来同步源码的,下载源码使用命令:

$ repo sync

大概要下载4G多的文件,所有下载过程会比较长。

非常重要的,下载完成之后需要打几个补丁,请分别执行以下命令,按顺序打以下四个补丁:
cd build
git pull git://android.git.kernel.org/platform/build refs/changes/74/12074/3

cd system/core
git pull git://android.git.kernel.org/platform/system/core refs/changes/45/11845/3

cd external/qemu
git pull git://android.git.kernel.org/platform/external/qemu refs/changes/46/11846/3

cd system/core
git pull git://android.git.kernel.org/platform/system/core refs/changes/97/12597/1

3.下载并安装XCode和MacPorts

首先下载安装最新的XCode,下载地址:http://developer.apple.com
然后下载MacPorts,下载地址: http://www.macports.org/
修改~/.profile文件,添加:
# set the number of open files to be 1024
ulimit -S -n 1024

4.编译源码

首先修改~/.profile文件,内容类似:
# MacPorts Installer addition on 2010-05-19_at_19:14:53: adding an appropriate PATH variable for use with MacPorts.
export ANDROID_PRODUCT_OUT=/Volumes/android/Android-Source/out/target/product/generic
export ANDROID_PRODUCT_OUT_BIN=/Volumes/android/Android-Source/out/host/darwin-x86/bin
export PATH=/opt/local/bin:/opt/local/sbin:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT}:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

# MacPorts Installer addition on 2010-05-19_at_19:14:53: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.

然后打开一个新的命令行窗口,执行以下命令:
$ cd /Volumes/android/Android-Source
$ make
源码编译时间较长,大概需要4~5个小时,请耐心等待,编译完成之后,执行命令:
$ emulator
将 调出模拟器,说明编译成功!

1. 打最后补丁时出错,错误如下:
    “Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use ‘git add/rm ‘
as appropriate to mark resolution, or use ‘git commit -a’.”
    改用命令:
   “git clone git://android.git.kernel.org/platform/system/corerefs/changes/97/12597/1″






出错原因:
./external/elfutils/config-compat-darwin.h:42: error: static declaration of ‘strnlen’ follows non-static declaration
/usr/include/string.h:143: error: previous declaration of ‘strnlen’ was here
make: *** Error 1

解决方案:参考别人些的文章
http://blog.sephiroth.it/2011/10/17/compiling-android-source-on-mac-lion/

modify ./external/elfutils/config-compat-darwin.h.
replace:







static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen-- && *__string++)
len++;
return len;
}
with:








#if 0
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen-- && *__string++)
len++;
return len;
}
#endif
Well, at the end of the process I just edited the Android.mk makefile into external/skia adding a new entry for BUILD_STATIC_LIBRARY and the next command was simply:

mmm external/skia
which produced the required libskia.a file to be linked in my project.









第二个问题:
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:


Do this by commenting out all lines in

external/qemu/Android.mk


The toolchain problem stems from the fact that Android actually supports the mac toolchain from Snow Leopard and onwards. So put homebrew path LAST in $PATH, so that it uses the Mac toolchain first.

When building DevNull/Oxygen ROM you in addition to the steps above also need to make a symlink in /usr/local/bin from sed to gsed, since they explicitly call gsed at one point. Also you have to disable WITH_DEXPREOPT like so:
make -j8 [devnull] WITH_DEXPREOPT=false
页: [1]
查看完整版本: Mac OS X 下android源码编译