在这里记录一下在Mac High Sierra编译Android7.1以后源码出现的坑以及解决方法.
编译Android 7.1出现
[ 1% 629/33105] Yacc: aidl <= system/tools/aidl/aidl_language_y.yy
FAILED: /bin/bash -c "prebuilts/misc/darwin-x86/bison/bison -d --defines=out/host/darwin-x86/obj/STATIC_LIBRARIES/libaidl-common_intermediates/aidl_language_y.h -o out/host/darwin-x86/obj/STATIC_LIBRARIES/libaidl-common_intermediates/aidl_language_y.cpp system/tools/aidl/aidl_language_y.yy"
/bin/bash: prebuilts/misc/darwin-x86/bison/bison: No such file or directory
[ 1% 629/33105] host SharedLib: libcr...rwin-x86/obj/lib/libcrypto-host.dylib)
ld: warning: -read_only_relocs cannot be used with x86_64
[ 1% 629/33105] host Java: guavalib (...RARIES/guavalib_intermediates/classes)
警告: [options] 未与 -source 1.7 一起设置引导类路径
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
1 个警告
[ 1% 629/33105] target Java: core-all...RARIES/core-all_intermediates/classes)
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1
Android 8.1是这样的
[ 0% 310/89583] //external/selinux/ch...eckpolicy yacc policy_parse.y [darwin
FAILED: out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h
BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d --defines=out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.h -o out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/policy_parse.c external/selinux/checkpolicy/policy_parse.y
[ 0% 317/89583] //system/core/bootstat:bootstat clang++ bootstat.cpp
ninja: build stopped: subcommand failed.
12:58:42 ninja failed with: exit status 1
这两个错误都是由于bison不能正常使用导致的。可以使用
./prebuilts/misc/darwin-x86/bison/bison
检测一下你的源码中的bison是否正常工作。
网上有一些国内复制粘贴的解决办法但我没有走通,下面是我在谷歌搜索到的解决方案:
1、定位到源码中external/bison文件夹
cd external/bison
2、在文件夹创建文本文件patch-high-sierra.patch并把下面代码复制进去()
With format string strictness, High Sierra also enforces that %n isn't used
in dynamic format strings, but we should just disable its use on darwin in
general.
--- lib/vasnprintf.c.orig 2017-06-22 15:19:15.000000000 -0700
+++ lib/vasnprintf.c 2017-06-22 15:20:20.000000000 -0700
@@ -4869,7 +4869,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *
#endif
*fbp = dp->conversion;
#if USE_SNPRINTF
-# if !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
+# if !defined(__APPLE__) && !(((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
fbp[1] = '%';
fbp[2] = 'n';
fbp[3] = '\0';
3、在控制台(保证当前目录是external/bison)执行
patch -p0 < patch-high-sierra.patch
4、返回根目录
cd ../..
5、编译bison
make bison
6、复制bison到AOSP编译时寻找bison的位置
cp ./out/host/darwin-x86/obj/EXECUTABLES/bison_intermediates/bison ./prebuilts/misc/darwin-x86/bison/bison
经过我自己的验证在7.1以后的版本都需要使用这个来解决bison失效的问题,至少现在还是这样的。报的类似错误都可以用这个方式试试
编译到最后报错
Created filesystem with 39/35200 inodes and 7290/140800 blocks
stat: cannot read file system information for '%z': No such file or directory
/bin/bash: File: "out/target/product/generic/userdata.img"
ID: 100000a00000017 Namelen: ? Type: hfs
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 80212992 Free: 50854175 Available: 50854175
Inodes: Total: 4294967279 Free: 4294163940
+
0 : syntax error in expression (error token is ": "out/target/product/generic/userdata.img"
ID: 100000a00000017 Namelen: ? Type: hfs
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 80212992 Free: 50854175 Available: 50854175
Inodes: Total: 4294967279 Free: 4294163940
+
0 ")
[ 84% 27299/32477] target Package: Set...PS/Settings_intermediates/package.apk)
nothing matches overlay file suw_navbar_ic_back.xml, for flavor anydpi-v21
nothing matches overlay file suw_navbar_ic_more.xml, for flavor anydpi-v21
nothing matches overlay file suw_navbar_ic_next.xml, for flavor anydpi-v21
nothing matches overlay file suw_progress_bar.xml, for flavor v21
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1
修改文件:
build/core/combo/HOST_darwin-x86.mk
Mac需要把最后替换为:
# $(1): The file to check
define get-file-size
GSTAT=$(which gstat) ; \
if [ ! -z "$GSTAT" ]; then \
gstat -c "%s" $(1) ; \
else \
stat -f "%z" $(1) ; \
fi
endef
其他坑自行百度,我没有遇到,不过我已经把Xcode降级到8.1了。
切换分支:
1, 查看可切换的分支
在AOSP目录下
cd .repo/manifests
git branch -a | cut -d / -f 3
2,切换分支(以android-8.1.0_r15为例)
repo init -b android-8.1.0_r15
3,同步代码
repo sync
因为本地代码在Mac下编译需要改动,所以出现下面类似错误:
error: Cannot remove project “build”: uncommitted changes are present
commit changes, then run sync again
这里我使用网上的”repo forall platform/docs/source.android.com -c ‘git reset –hard ;
git clean -fdx’”是没有用的,所以我进入build目录用Git提交了一下,重新repo sync就好了。