设为首页 收藏本站
查看: 1157|回复: 0

[经验分享] Mac OS X 下android源码编译

[复制链接]

尚未签到

发表于 2016-5-15 13:40:21 | 显示全部楼层 |阅读模式
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/core  refs/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: *** [out/host/darwin-x86/obj/STATIC_LIBRARIES/libelf_intermediates/lib/xmalloc.o] 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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-217340-1-1.html 上篇帖子: Mac OS X工具:版本控制SVN 下篇帖子: MacPorts安装和使用--Mac OS X
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表