现在的位置: 首页 > 综合 > 正文

Mac OS X 10.6下android源码编译

2013年09月03日 ⁄ 综合 ⁄ 共 2797字 ⁄ 字号 评论关闭

Mac OS X 10.6下android源码编译

1.需要至少8G大的大小写敏感分区

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

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

  或者使用磁盘工具创建dmg映像文件,步骤如下:

  1)在Finder中启动/应用程序/实用工具/磁盘工具;

  2)选择新建映像;

  3)选择目标位置,一般选择放在用户自己的目录下;

  3)大小选自定义:8G;

  4)格式选 Mac OS扩展(区分大小写,日志式)。

  然后编辑你的 ~/.bash_profile文件,没有则创建它,添加如下内容:

  # command to mount the android file image
  function mountAndroid  { hdiutil attach ~/android.dmg  -mountpoint /Volumes/android; }

  之后你就可以使用mountAndroid挂载你的镜像文件到/Volumes/android目录下了。
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/ 运行tar -zxvf tarfilename命令解压,切换到解压后的目录并安装:
  $ ./configure
  $ make
  $ sudo make install
然后修改~/.bash_profile文件,添加:
export PATH=/opt/local/bin:$PATH
然后执行命令让MacPort自更新:
$ sudo port selfupdate
从port中安装需要的包
$ POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg
更新GNU到最新版本:
$ sudo ln -s gmake /opt/local/bin/make

  修改~/.bash_profile文件,添加:
  # set the number of open files to be 1024
  ulimit -S -n 1024
4.编译源码

  首先修改~/.bash_profile文件,添加:
  PATH=$PATH:/Volumes/android/android/bin
  #JAVA_HOME=/usr/bin
  JAVA_HOME=/Library/Java/Home
  ANDROID_PRODUCT_OUT=/Volumes/android/android/out/target/product/generic
  ANDROID_PRODUCT_OUT_BIN=/Volumes/android/android/out/host/darwin-x86/bin
  PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT}:~/eclipse
  export PATH JAVA_HOME ANDROID_PRODUCT_OUT
  然后打开一个新的命令行窗口,执行以下命令:
  $ cd /Volumes/android/android
$ make
  源码编译时间较长,大概需要4~5个小时,请耐心等待,编译完成之后,执行命令:
  $ emulator
将 调出模拟器,说明编译成功!
5.常见错误,欢迎反馈!

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/core  refs/changes/97/12597/1″

抱歉!评论已关闭.