MAC下载编译Android源码及BUG

前言

配置如下:

MAC 10.13 
xcode: Version 9.2
jdk: 1.8.0_131
android源码版本: android-8.1.0_r1

最后下载完,.repo 约30G,代码约30G,编译过后整个文件夹约150G,out文件夹下占80G。

我试过其他几个版本,能下载但是编译都不成功,只有这个版本成功,建议大家慎重选择版本。

嫌麻烦的朋友可以下载我的源码,但是需要自己编译。
下载地址

环境配置

google 官方文档:https://source.android.com/source/initializing
建议至少腾出150G的空间。

配置BUG

1.gnupg过时
Error: gnupg has been deprecated. If you absolutely want to stay on the classic version, install the gnupg1 port. All other users are recommended to install gnupg2.
Error: Failed to configure gnupg: obsolete port
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_mail_gnupg/gnupg/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets to report a bug.
Error: Processing of port gnupg failed

由于gnupg已经过时,如果要继续使用gnupg的话,改为下载gnupg1;Error中建议大家使用gnupg2,我用的就是gnupg2。需要先关闭gnupg1的端口。

POSIXLY_CORRECT=1 sudo port uninstall gnupg1
POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg2

下载方法

google 官方渠道:https://source.android.com/source/downloading
需要科学上网,但是我的SSR能科学上网但是不能下载源码,最后换了VPN才能正常下载。

下载BUG

1. 找不到repo
repo: command not found

解决办法:直接输入

echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc  
export PATH=$PATH:$HOME/bin 
2. 无法连上https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 60] Operation timed out

从Google下载源码时需要科学上网,或者VPN配置不对,无法下载

3. 无法检查签名:找不到公钥
object eceeb1b1f5edb0f42e690bffdf81828abd8ea7fe
type commit
tag v1.12.37
tagger Dan Willemsen <dwillemsen@google.com> 1475173621 -0700

repo v1.12.37

gpg: 钥匙环‘/Users/dengjiaming/.repoconfig/gnupg/pubring.gpg’已建立
gpg: 签名建立于 五  9/30 02:27:01 2016 CST
gpg:               使用 DSA 密钥 16530D5E920F5C65
gpg: 无法检查签名:找不到公钥

出现此问题是因为repo版本不对,删除用户目录下的.repoconfig,再repo init,问题解决。

4.
Get https://android.googlesource.com/platform/manifest  
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
                                 Dload  Upload   Total   Spent    Left  Speed  
  0     0    0     0    0     0      0      0 --:--:--  0:00:06 --:--:--     0  
curl: (22) The requested URL returned error: 404  
Server does not provide clone.bundle; ignoring.  

问题暂时可忽略

5.修改default.xml

为了能够更加快捷的下载源码,接下来我们需要修改 .repo/manifests/default.xml 中的内容了。

如果仔细看过该文件的内容的话,会发现其实有部分 project 标签下是有配置 clone-depth=”1”。

这个配置的意思是, 在 git clone 源码的时候只 clone 最新的这一层, 不 clone 历史的文件记录这些, 加上这个配置就能很快的 clone 源码了.

所以接下来我们就是需要为每个 project 标签都加上 clone-depth=”1”的配置。

于是上网找了以下代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

file_object = open('default.xml')

change_content = ''
while 1:
    line = file_object.readline()
    if not line.__contains__('clone-depth'):
        try:
            endpos = line.index("/>")
            line = line[0:endpos] + ' clone-depth="1"' + line[endpos: line.__len__()]
            pass
        except Exception, e:
            pass

    change_content += line
    if not line:
        break
    pass  # do something

print change_content

我们不需要再源码目录下修改这些文件,在其他地方创建一个 default.xml 文件,把 .Repo中的 default.xml 中的含有 project 标签的内容复制到刚刚创建的文件中。

接下来执行 python 脚本就就可以在命令行下面看到修改好的 project 标签,我们把这些标签替换掉.Repo中的 default.xml project 标签即可。

6.下载源码

修改完default.xml文件后,就可以开通下载源码了,为了断线后或者出现异常情况后依然能够下载源码,于是上网找了以下代码:

#!/bin/bash 
#FileName  syn.sh

repo sync 
while [ $? = 1 ]; do 
echo "================sync failed, re-sync again =====" 
sleep 3 
repo sync 
done

把上面的内容复制到与 .repo 同一个文件夹中的 syn.sh。

chmod a+x syn.sh
./syn.sh

编译方法

google 官方文档:https://source.android.com/source/building
编译时间大约3个小时,选择的版本是aosp_sailfish-userdebug。

编译BUG

1.
internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12"]
ninja: build stopped: subcommand failed.
20:37:11 soong bootstrap failed with: exit status 1
make: *** [run_soong_ui] Error 1

https://github.com/phracker/MacOSX-SDKs/releases 下载”10.10” “10.11” “10.12”的其中一个sdk,解压后,放到/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs中,并且创建名为MacOSX10.12.sdk 的快捷方式。

创建方法:

sudo ln -s MacOSX10.12 MacOSX10.12.sdk
2.
[  2% 2088/81667] yacc out/soong/.inte.../system/tools/aidl/aidl_language_y.cpp
FAILED: out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h 
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d  --defines=out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.h -o out/soong/.intermediates/system/tools/aidl/libaidl-common/darwin_x86_64_static/gen/yacc/system/tools/aidl/aidl_language_y.cpp system/tools/aidl/aidl_language_y.yy
[  2% 2095/81667] lex out/soong/.inter.../system/tools/aidl/aidl_language_l.cpp
ninja: build stopped: subcommand failed.
21:43:47 ninja failed with: exit status 1
make: *** [run_soong_ui] Error 1

解决方法:

Patch [bison fix](https://android-review.googlesource.com/c/platform/external/bison/+/517740) for High Sierra and build bison:

    1. cd /Volumes/AOSP/external/bison
    2. git cherry-pick c0c852bd6fe462b148475476d9124fd740eba160
    3. mm

Replace prebuilt bison binary with patched binary

    1. cp /Volumes/AOSP/out/host/darwin-x86/bin/bison /Volumes/AOSP/prebuilts/misc/darwin-x86/bison/

Build

    1. make  -j8

如果mm命令无法执行,需要回去执行以下命令

1. source build/envsetup.sh
2. lunch 
# 之后回到external/bison目录
3. mm
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值