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

[经验分享] Building android AOSP on Mac OS X Mountain Lion

[复制链接]

尚未签到

发表于 2015-12-30 12:51:21 | 显示全部楼层 |阅读模式
  I have been working with the Android AOSP source code for some time now and spent endless hours searching the internet for problems that arose on different occasions. Today I decided to note them down, on the one hand it is convenient for me to just look it up on my own blog, on the other hand you might find some of these notes useful.
  What I ran into today was upgrading from Android 4.0.3 to 4.2.2. I didn't expect any difficulties in compiling the new source as compiling Android 4.0.3 on my Mac OS X (Mountain Lion) worked like a charm for me. But of course I discovered something disturbing - when I ran lunch 12, I got an error:



xcrun: Error: failed to exec real xcrun. (No such file or directory)
build/core/combo/HOST_darwin-x86.mk:62: *****************************************************
build/core/combo/HOST_darwin-x86.mk:63: * Cannot find SDK 10.6 at /Developer/SDKs/MacOSX10.6.sdk
build/core/combo/HOST_darwin-x86.mk:65: * If you wish to build using higher version of SDK,
build/core/combo/HOST_darwin-x86.mk:66: * try setting BUILD_MAC_SDK_EXPERIMENTAL=1 before
build/core/combo/HOST_darwin-x86.mk:67: * rerunning this command
build/core/combo/HOST_darwin-x86.mk:69: *****************************************************
build/core/combo/HOST_darwin-x86.mk:70: *** Stop..  Stop.
** Don't have a product spec for: 'full_maguro'
** Do you have the right repo manifest?
What the hell is it complaining about?
  Quickly looking up what xcrun is doing I discovered it's some helper program do select the correct XCode version/sdk etc. It didn't suprise me that it failed as I don't have XCode installed. But why would it want somthing from XCode?
  I don't really have an answer to that, but I discovered that some genius decided that everyone building on Mac OS X has XCode installed. There's no option nor flag nor anything else to disable the use of these XCode specific tools - at least I didn't find them. However, I don't want to complain about it (too much) so without further ado I'll tell you how to compile Android 4.2.2 on Mac OS X Mountain Lion. I'll even try to do it in a way that you can do it when starting from scratch. Please keep in mind that I had my system running for a long time so I might have missed some steps when trying to backtrack the essentials.

Setting up the build environment
  At this point I should point out that there is an excellent documentation for setting up the environment here and if anything goes wrong you should check it and it might solve your problem.

Homebrew and Prequesites
  I am using brew to install packages that are not shipped with the os and will setup the build environment using it. Of course you are free to use whatever you prefer, but I can highly recommend brew. After your system is ready to brew (check it with brew doctor), execute the following commands:



brew install automake
brew tap homebrew/dupes
brew install apple-gcc42
  Moreover you have to install Java 1.6, for that just open the Terminal and type java -version. If you haven't installed it the system will prompt you whether you want to install it.

Prepare a virtual disk to hold the android source
  The default file system on Mac OS X is case-insensitive, meaning that Test and test would refer to the same file or directory. For some reason there are files in the linux kernel that differ only in the case of a letter - this is something you'd probably do after 72 hours of not sleeping and having a few drinks, at least that's the situation I imagine when trying to grasp why someone would do that... Anyhow, either you have a disk with a case-sensitive filesystem or you create a virtual disk and mount it. To create the virtual disk, mount it and enter the directory run:



hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/android.dmg
hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android
cd /Volumes/android
Downloading the source
  First we need to install repo which is a program that helps to organize the git repositories.



mkdir ~/bin
PATH=~/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
  If you have followed along, you're still in the root directory of the mounted disk. If not you'll have to cd /Volumes/android. Finally to download the code run:



repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.2_r1.2 --config-name
repo sync
  This will take a while, go do something else until it finishes.

Building for a device
  These steps depend on the device you're building for, I will give you the steps for Galaxy Nexus (maguro) and you have to adapt them accordingly. First download the necessary drivers from the nexus driver page and extract them to /Volumes/android. Now you should have a directory listing similar to this one:



$ cd /Volumes/android
$ ls
Makefile            external            libcore
abi                extract-broadcom-maguro.sh    libnativehelper
bionic                extract-imgtec-maguro.sh    ndk
bootable            extract-invensense-maguro.sh    out
build                extract-nxp-maguro.sh        packages
cts                extract-samsung-maguro.sh    pdk
dalvik                extract-widevine-maguro.sh    prebuilts
development            frameworks            sdk
device                gdk                system
docs                hardware            vendor
  Now run each of the extract-... shell scripts. You will be asked to accept its license and you should (well, otherwise the drivers won't be extracted). Also you might have to unlock your bootloader etc. but I'll leave that to you; it's a well documented procedure.

Building the source code
  Just to be on the safe side, the android build scripts depend on being executed by bash therefore run it if you don't already. Moreover I had problems withperlbrew, if you have it installed it'd be wise to switch to the perl version that is shipped with Mac OS X now.
  Now there comes the time for the hack, download this file ( android-4.2.2_r1.2 only !!! ) and overwrite the file in build/core/combos/HOST_darwin-x86.mk. I changed the file to allow for manually overriding the host compilers HOST_CC and HOST_CXX and skip the xcode test if they are both present. I don't use makefiles at all so there might be a more elegant solution to the problem but this works. After you have replaced the files you can execute:



. build/envsetup.sh
HOST_CC=gcc-4.2 HOST_CXX=g++-4.2 lunch
make HOST_CC=gcc-4.2 HOST_CXX=g++-4.2 -j8
  This will again take a while and if you followed all the steps the compilation succeeds.

Final Notes
  Most of the steps I presented here are from the official android documentation and I recommend reading these docs for further information or troubleshooting. I hope I could help some of you :)

运维网声明 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-158336-1-1.html 上篇帖子: Mac OS X Mavericks使用手册 下篇帖子: 在mac os x中建立事件钩子
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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