Android 源码编译 MacOS X环境
来源:互联网 发布:wingide for mac 破解 编辑:程序博客网 时间:2024/06/08 17:57
一、下载源代码
1. 创建目录~/bin
mkdir ~/bin
添加以下命令到~/.bash_profile
export PATH=~/bin:$PATH
2. 安装repo,这里没用安装官网文档来
$ curl https://git-repo.googlecode.com/files/repo-1.19 > ~/bin/repo
然后修改repo为可执行权限
chmod a+x ~/bin/repo
3. 为了方便下载,修改repo文件,如下
#REPO_URL = 'http://gerrit.googlesource.com/git-repo'
REPO_URL='http://code.google.com/p/git-repo/'
4. 创建个源码目录mkdir android-source准备下载
cd android-source
5. 执行repo init, git库和官网的不一样,原因不解释。从master 下载源码
repo init -u git://Android.git.linaro.org/platform/manifest.git 或者分支上下载
repo init -u git://Android.git.linaro.org/platform/manifest.git -b “branch tag”
我选择的是比较新的android-4.4.2_r1
repo init -u git://Android.git.linaro.org/platform/manifest.git -b android-4.4.2_r1
可以在https://source.android.com/source/build-numbers.html 官网查看你想要下载的源码对应的tag
执行完之后,在本地会有个目录.repo,然后在android-source目录下执行repo sync下载代码。下载代码需要很长时间,如果感觉没用继续下载,可以ctrl+c杀掉,继续执行repo sync 直到下载完成。下载完成后,android-source下一共27G,.repo 17G, 源码10G左右。
二、Mac OS X(10.9.2)编译环境设置1. 创建大小写敏感的磁盘镜像
在Mac下编译android的源代码需要一个大小写敏感(Case Sensitive)的分区格式如果你原来的分区不是HFS+一类大小写敏感的文件格式,那么最简单的办法就是新建一个这种分区格式的dmg出来,命令如下:
sudo hdiutil create -size 40g -type UDIF -fs HFSX -volname android /android.dmg
sudo chown $USER /android.dmg
然后打开Finder用鼠标双击/android.dmg,Mac系统将会自动加载android.dmg。在Finder 的右侧“Devices” 目录栏下你将会看到android.dmg磁盘,双击打开 。一定要注意:必须将源码压缩包复制到android.dmg磁盘,再解压缩;不能在Mac普通磁盘区解压缩,然后再copy到android.dmg, 因为Mac默认是不区分文件名大小写的,解压出来的一些文件可能被重名的文件覆盖而丢失。
2. 需要安装的工具make 3.81版本: make 3.82版本有bug,需要退回3.81. 通过以下命令确认版本
$make -v
3. 修改文件描述符限制
在~/.bash_profile中添加以下内容
# set the number of open files to be 1024
ulimit -S -n 1024
三、编译源码
将代码从android-source目录拷贝到挂载的之前创建的分区/Volumes/android,然后在这个分区下可以删除.repo目录,这个目录在编译代码时,没用并且占去很多空间.
1. 初始化编译环境
$source build/envsetup.sh
2. 选择编译目标,具体查阅http://source.android.com/source/building-running.html
$lunch full-eng
3. 编译整个源代码
$make 或者 $make -j4
4. 其它编译命令:
$ make clean //清除之前编译的所有结果$ make systemimage //编译system.img$ make userdataimage //编译userdata.img$ make ramdisk //编译ramdisk.img$ make snod //重新打包生成system.img,不编译只打包$ make sdk //编译SDK,生成的SDK在out/host/linux-x86/SDK目录下$ make PRODUCT-sdk-sdk //编译SDK,这个方法解决了之前使用”make sdk”命令编译SDK的一个bug。编译sdk不要直接用make sdk.$ make update-api //如果你修改了Android源码中标识为@hide的方法或类,你需要这些内容编译进SDK的Document中的话,这个命令是必须的$ m //相当于make$ mm //编译当前目录下所有模块$ mmm packages/apps/Music //编译指定目录下所有模块5. 在模拟器中运行镜像:
编译好android之后,emulator在~/android/out/host/linux-x86/bin下,首先设置环境变量:
export ANDROID_PRODUCT_OUT=/Volumes/android/android_4_4_2/out/target/product/generic export ANDROID_PRODUCT_OUT_BIN=/Volumes/android/android_4_4_2/out/host/linux-x86/binexport PATH=$PATH:$ANDROID_PRODUCT_OUT_BIN:$ANDROID_PRODUCT_OUT然后就可以启动模拟器了:
$cd ~/android/out/host/linux-x86/bin$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img
执行emulator 命令时,如果不带任何参数,则Kernel镜像默认使用~/Android/prebuilt/android-arm/kernel目录下的kernel-qemu文件,而Android镜像则默认使用~/android/out/target/product /generic目录下的system.img、userdata.img和ramdisk.img,模拟器运行需要这四个文件。
6. 启动模拟器遇到的问题:
(1)按照上面的步骤,在Android-2.3以下只要设置了ANDROID_PRODUCT_OUT环境变量emulator就可以使用了,但是在android 4.1以上就不能使用了,只有刚刚make结束的时候的终端可以直接运行,新开一个终端就不行了,出现以下提示:
emulator: ERROR: You did not specify a virtual device name, and the systemdirectory could not be found.If you are an Android SDK user, please use '@<name>' or '-avd <name>'to start a given virtual device (see -help-avd for details).Otherwise, follow the instructions in -help-disk-images to start the emulator在/externel/qemu/android/main-common.c 发现如下代码:
AvdInfo* createAVD(AndroidOptions* opts, int* inAndroidBuild) { android_build_root = getenv("ANDROID_BUILD_TOP"); if (android_build_root == NULL || android_build_root[0] == 0) break; ……}因此解决方法是设置ANDROID_BUILD_TOP环境变量:
export ANDROID_BUILD_TOP=/Volumes/android/android_4_4_2export ANDROID_PRODUCT_OUT=/Volumes/android/android_4_4_2/out/target/product/genericexport ANDROID_PRODUCT_OUT_BIN=/Volumes/android/android_4_4_2/out/host/darwin-x86/binexport PATH=$PATH:$ANDROID_PRODUCT_OUT_BIN:$ANDROID_PRODUCT_OUT:$ANDROID_BUILD_TOP(2) 按照上述方法设置环境变量后,启动emulator 仍然报错。有一点需要大家注意:如果你的PC之前安装过Android SDK(官网下载的)并且已经设置了环境变量,$emulator 命令可能会定位到你之前安装的Android SDK目录下,而不是ANDROID_PRODUCT_OUT_BIN目录。这个问题我自己折腾了好半天,最终才发现原因。所以最好的办法是启动模拟器时指定完整路径:
$/Volumes/android/android_4_4_2/out/host/linux-x86/bin/emulator -system /Volumes/android/android_4_4_2/out/target/product/generic/system.img -data /Volumes/android/android_4_4_2/out/target/product/generic/userdata.img -ramdisk /Volumes/android/android_4_4_2/out/target/product/generic/ramdisk.img
运行上述命令,模拟器成功启动,那个心情激动啊......
7. 编译过程中遇到的问题
(1) Build error : SyntaxError: Unable to find any JNI methods for org/chromium/ui/Clipboard
解决方法:修改/android_source/external/chromiun_org/base/android/jni_generator/jni_generator.py,如下
https://github.com/CyanogenMod/android_external_chromium_org/commit/5130af630390487b37d99941887883647c67f37a
- Android 源码编译 MacOS X环境
- MacOS X编译OpenSceneGraph
- Android源码编译环境
- android源码编译环境,应用程序编译环境
- Cocos2d-x编译Android环境
- MacOS X 10.6 下 编译APUE代码清单(apue.2e 第二版源码)
- MacOS X 10.8 下 编译APUE代码清单(apue.2e 第二版源码)
- Android内核源码学习:1、MacOS 编译Android源码-工具
- Android Studio工程如何放到Android 4.X源码环境中编译
- ubuntu环境源码编译android
- 搭建Android源码编译环境
- 搭建Android源码编译环境
- 搭建Android源码编译环境
- 搭建Android源码编译环境
- Android 源码编译环境搭建
- 搭建Android源码编译环境
- Android源码编译环境建立
- 搭建Android源码编译环境
- Android19_SQLiteOpenHelper
- 欢迎使用CSDN-markdown编辑器
- quick StateMachine 状态机的使用
- oracle小数不显示“0”问题的解决方法
- unbuntu10.04环境下安装jdk1.7
- Android 源码编译 MacOS X环境
- Unity4.6新UI系统初探(uGUI)
- 下载精确卫星星历文件 2015.3.31
- The server encountered an internal error that prevented it from fulfilling this request. exception
- 特性
- 页面 jQuery
- 禁用emoji表情
- 安装centos5.6-i386-mini--linux安装(一)
- Java基础--封装、继承、多态