Mac下载并编译Google安卓AOSP项目代码

参考 https://source.android.com/source/index.html

这两天用Mac下载安卓AOSP源码,且把遇到的问题记下来。当然作为一个菜鸟,难免会有错误或者描述不对的地方,欢迎各路大神小神批评指正。转载请注明出处http://www.cnblogs.com/ryanchi/p/5682186.html

一、准备环境

(请提前安装好xcode或command line tools)

  • Installing the JDK

    The master branch of Android in the Android Open Source Project (AOSP) requires Java 8

  • Creating a case-sensitive disk image

    执行下面命令,将会在/Users/当前用户/目录下创建android.dmg文件,当然也可以自己定义文件位置。

    $ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/android.dmg

    This will create a .dmg (or possibly a .dmg.sparseimage) file.

    官方文档推荐40GB,后来发现完全不够用,这里我直接上100g,并且文件位置直接放在桌面,下次开机时直接双击打开,虽然MBP经常不关机。。。

    $ hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 100g ~/Desktop/android.dmg

    • 如果你镜像创建完毕,想改变镜像大小,可以执行下面代码:

      $ hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimage

    • 你可以为bash添加function,以便快速挂载和卸载android.dmg文件。但如果和我一样偷懒镜像文件直接放桌面,则可以省略这一步,直接从桌面装载镜像就行。

        # mount the android file image
      function mountAndroid { hdiutil attach ~/android.dmg -mountpoint /Volumes/android; }
      # unmount the android file image
      function umountAndroid() { hdiutil detach /Volumes/android; }

二、Installing required packages

  1. Install MacPorts from macports.org

    直接下载MacPorts_xxx.pkg文件安装即可(xxx为版本号)。

    Note: Make sure that /opt/local/bin appears in your path before /usr/bin。可以通过$ echo $PATH命令查看。如果不是,在~/.bash_profile文件中添加下面代码,添加完毕后直接执行$ source ~/.bash_profile命令。

	export PATH=/opt/local/bin:$PATH	

* 我的情况是MacPorts_xxx.pkg安装完毕后,其自动在`~/.bash_profile`文件里添加了`export PATH="/opt/local/bin:/opt/local/sbin:$PATH"`
  1. Get make, git, and GPG packages from MacPorts:

    $ POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg

    报错:

     Error: Port gmake not found

    执行$ sudo port -d sync即可。

    若执行上述命令继续报如下错误:

     receiving file list ... rsync: read error: Operation timed out (60)
    Error: Synchronization of the local ports tree failed doing rsync
    port sync failed: Synchronization of 1 source(s) failed
*解决办法:*
> 修改 `/opt/local/etc/macports/sources.conf`,将原来最后一行修改成如下,然后执行`$ sudo prot -v selfupdate`即可。
	#rsync://rsync.macports.org/release/tarballs/ports.tar [default]
https://distfiles.macports.org/ports.tar.gz [default]

三、下载源码

  • Installing Repo

     $ mkdir ~/bin		# 在当前用户目录新建bin\文件夹
    $ PATH=~/bin:$PATH # 将bin目录添加到PATH $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo
  • Downloading the Android Source Tree

    考虑到国内网络问题,这一步骤可以参考清华大学镜像资源站https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/的教程,写的很详细。

    1. 下载AOSP月更新的初始化包,https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar

    2. 解压。将下载得到的aosp-latest.tar压缩文件直接拷贝到前面创建的xxx.dmg镜像文件装载的磁盘目录,执行$ tar xf aosp-latest.tar,稍等解压完毕后,当前目录会出现一个AOSP文件夹,该文件夹下有一个隐藏文件夹.repo

    3. 同步代码树。执行$ repo sync。具体可以参考下面步骤:

       wget https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
      tar xf aosp-latest.tar
      cd AOSP # 解压得到的 AOSP 工程目录
      # 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
      repo sync # 正常同步一遍即可得到完整目录
      # 或 repo sync -l 仅checkout代码

四、Build

  1. Clean up

    To ensure the newly installed binaries are properly taken into account after being extracted, delete the existing output of any previous build using:

     $ make clobber

    报错

     Error: could not find jdk tools.jar at /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/../lib/tools.jar, please check if your JDK was installed correctly.  Stop.

    解决办法:参考关于完整Android源码的阅读~/.bash_profile文件中指定ANDROID_JAVA_HOME为JDK路径即可。

     export ANDROID_JAVA_HOME=${JAVA_HOME}
  2. Set up environment

     $ source build/envsetup.sh
  3. Choose a target

     $ lunch aosp_arm-eng
    ildtype Use
    er limited access; suited for production
    erdebug like "user" but with root access and debuggability; preferred for debugging
    g development configuration with additional debugging tools

    可选的有aosp_arm-eng、 aosp_arm64-eng、aosp_mips-eng、aosp_mips64-eng、aosp_x86-eng......

  4. Build the code

     $ make -jN

    N为数字,一般为cpu线程数1到2倍。我的本本是mbp2015年中,使用$ make -j8,很多warning,不管即可,用了一个多小时,最后输出结果#### make completed successfully (01:06:05 (hh:mm:ss)) ####

  5. Emulate an Android Device

    运行模拟器

     $ emulator

五、Building Kernels

到了这里,略坑。由于需要克隆谷歌git仓库到本地,所以配置完git的http代理以后,到AOSP项目中,cd进入kernel文件夹,直接

$ git clone https://android.googlesource.com/kernel/goldfish.git

等了一晚,结果如下:

remote: Sending approximately 982.87 MiB ...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: 过早的文件结束符(EOF)
fatal: index-pack failed

由于使用的梯子不给力,试了好几次,都是clone了一部分后直接挂掉。。。所以现在正琢磨自己搭建ss服务器,同时也希望有好的梯子童鞋可以私聊推荐一下。内核这部分内容可以参考谷歌https://source.android.com/source/building-kernels.html或者罗升阳老师的博客 在Ubuntu上下载、编译和安装Android最新内核源代码(Linux Kernel)

THE END!

Mac下载并编译Google安卓AOSP项目代码的更多相关文章

  1. lunix或者centos服务器下如何下载自己在github上面的项目代码

    1.在github找到项目压缩包下载地址 打开自己的github主页找到需要下载的项目首页,如图所示,找到zip下载地址(ps:如何找这个地址我就不多说了,了解过一点html的同学肯定很容易可以找到) ...

  2. Android 7.1.1系统源码下载、编译、刷机-Nexus 6实战

    想成为一位合格的Android程序员或者一位Android高级工程师是十分有必要知道Android的框架层的工作原理,要知道其工作原理那么就需要阅读Android的源代码. 想要阅读Android的源 ...

  3. Google Code项目代码托管网站上Git版本控制系统使用简明教程

    作为一个著名的在线项目代码托管网站,Google Code目前主要支持三种版本控制系统,分别为Git, Mercurial和 Subversion.Subversion即SVN相信大家都已经熟知了,这 ...

  4. macOS(Sierra 10.12)上Android源码(AOSP)的下载、编译与导入到Android Studio

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  5. mac os 平台下载并编译android2.3.3源码

    现在在做有关android平台下的项目,最初对android环境各种不熟悉,搞了几个月终于有点眉目了,由于需要用到android本身提供的一些类似gps,tts等服务,单纯的看android提供的ja ...

  6. AOSP ON MAKO(在NEXUS 4上刷ANDROID 4.4 源代码包-下载/配置/编译/刷机)

    AOSP ON MAKO(在NEXUS 4上刷ANDROID 4.4 源代码包-下载/配置/编译/刷机) 特别感谢google官方文档及AOSP源代码开放 參考链接: https://source.a ...

  7. v8 google 下载及编译

    ubuntu环境下进行 参考文档: http://code.google.com/p/v8/wiki/BuildingWithGYP (一) 源码下载及编译 1, Google v8 官网:http: ...

  8. 在 Mac OS 上编译 FFmpeg

    本文转自:在 Mac OS 上编译 FFmpeg | www.samirchen.com 安装 Xcode 和 Command Line Tools 从 App Store 上安装 Xcode,并确保 ...

  9. Google的C++开源代码项目

    Google的C++开源代码项目 http://www.open-open.com/lib/view/open1413873531356.html v8  -  V8 JavaScript Engin ...

随机推荐

  1. Codeforces Round #205 (Div. 2) : A

    题意: 要求找到最少次数的交换次数使得两组数都是偶数: 很明显答案要么是0,要么是1,或者不管怎么交换都不行(-1): 所以: #include<cstdio> #define maxn ...

  2. Stanford Parser学习入门(1)-Eclipse中配置

    Stanford Parser是斯坦福大学研发的用于语法分析的工具,属于stanford nlp系列工具之一.本文主要介绍Standfor Parser的入门用法. 在Stanford官方网站下载最新 ...

  3. 横向技术分析C#、C++和Java优劣

    转自横向技术分析C#.C++和Java优劣 C#诞生之日起,关于C#与Java之间的论战便此起彼伏,至今不辍.抛却Microsoft与Sun之间的恩怨与口角,客观地从技术上讲,C#与Java都是对传统 ...

  4. Android 两个Activity进行数据传送 发送

    Activity1:: Intent intent= new Intent(this, OtherActivity.class); String name = "heyiyong" ...

  5. PendingIntent的Flags

    PendingIntent是一个Intent的描述.包装,给予了这个PendingIntent 的组件在指定的事件发生或指定的时间到达时启动Activty.Service或者Broadcast. 根据 ...

  6. Android开源项目发现--- 安全篇(持续更新)

    SQLCipher Sqlite加密工具 项目地址:https://github.com/sqlcipher/sqlcipher 帮助文档:http://sqlcipher.net/sqlcipher ...

  7. read by other session

    模拟场景: 同时开多个SESSION执行select * from test2; read by other session: 当会话必须等待其他会话将统一数据块读入缓冲存储器时,作为read by ...

  8. EntityFramework 异常 -- An entity object cannot be referenced by multiple instances of IEntityChangeTracker

    问题      在调用 DbSet 的 Attach()  方法时(与将 Entity 设置为 EntityState.Unchanged 状态等价)报告以下错误:      An entity ob ...

  9. java---Unicode-字符转换器

    实现一个字符(包括汉字)的简单互相转换: package cn.hncu.gui2; import java.awt.Button; import java.awt.Color; import jav ...

  10. 解决外部机器通过VM内ubuntu IP 无法访问vm内web服务的问题

    1. 2.i root@ubuntu:/home/udapeng# ifconfig root@ubuntu:/www/sentry# nano uwsgi.ini root@ubuntu:/www/ ...