尝试编译android8.0源码,记录一下过程和遇到的问题。
1. 下载,参考:https://source.android.com/setup/downloading。需要墙,好在公司有墙。事先是下载到一个exfat文件格式的移动硬盘,后来发现编译时git需要区分大小写的文件系统,编译报错。只能讲源码放在一个MAC扩展区分大小写分区的磁盘里。所以下载前先创建一个MAC OS扩展(区分大小写 日志式)的分区,大小300G,源码大概200G,主要是.repo太大了,下载完后如果后期不想再拉代码可以删除.repo文件,可以省几十G的空间。
2. 编译,参考:https://medium.com/@christopherney/building-android-o-with-a-mac-da07e8bd94f9 。首先创建java ,make等环境,一般搞开发的电脑都装好了。按照参考博客中的步骤build即可,出错时参考博客中的Troubleshooting。另外实际编译时还遇到了其他一些问题,这里记录一下:
错误1:
FAILED: out
/soong/build
.ninja
out
/soong/
.bootstrap
/bin/soong_build
-t -l out/.module_paths
/Android
.bp.list -b out
/soong
-n out -d out
/soong/build
.ninja.d -o out
/soong/build
.ninja Android.bp
internal error: Could not
find
a supported mac sdk: [
"10.10"
"10.11"
"10.12"
"10.13"
]
ninja: build stopped: subcommand failed.
系统版本不支持,打开文件build/soong/cc/config/x86_darwin_host.go
修改 darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.13",
}
添加10.14
darwinSupportedSdkVersions = []string{
"10.10",
"10.11",
"10.12",
"10.13",
"10.14",
}
问题2:
frameworks/av/media/libstagefright/DataSource.cpp:29:10: fatal error: 'media/stagefright/DataURISource.h' file not found
#include
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[ 23% 14456/61662] //frameworks/av/media/libstagefright/xmlparser:libstagefright_xmlparser clang++ MediaCodecsXmlParser.cpp
ninja: build stopped: subcommand failed.
22:37:30 ninja failed with: exit status 1
#### failed to build some targets (02:37:40 (hh:mm:ss)) ####
原因:include找不到相关的头文件media/stagefright/DataURISource.h,
办法:google上找DataURISource.h源码放在libstagefright/include/media/stagefright/目录下
问题3
[ 27% 12835/46148] Building with Jack: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex
FAILED: out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex
/bin/bash out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex.rsp
Out of memory error (version 1.3-rc7 'Douarn' (445000 d7be3910514558d6715ce455ce0861ae2f56925a by [email protected])).
Java heap space.
Try increasing heap size with java option '-Xmx
Warning: This may have produced partial or corrupted output.
[ 27% 12840/46148] Compiling SDK Stubs with Jack: out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jack
ninja: build stopped: subcommand failed.
23:53:38 ninja failed with: exit status 1
#### failed to build some targets (32:27 (mm:ss)) ####
原因:内存不够
办法:添加限制,输入如下命令:
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server
问题4:
external/iptables/extensions/../include/linux/netfilter_ipv4/ipt_ECN.h:13:10: fatal error: 'linux/netfilter/xt_DSCP.h' file not found
#include
Please check the filename user or lower case. Remember that the Android building process is case-sensitive.
In this case create a symbolic name xt_dscp.h for the original file xt_DSCP.h with the following command lines:
cd external/iptables/extensions/../include/linux/netfilter
ln -s xt_dscp.h xt_DSCP.h
[ 0% 212/24512] build out/target/product/generic/obj/FAKE/selinux_policy_intermediates/reqd_policy_mask.conf
FAILED: out/target/product/generic/obj/FAKE/selinux_policy_intermediates/reqd_policy_mask.conf
/bin/bash -c "m4 -D mls_num_sens=1 -D mls_num_cats=1024 -D target_build_variant=eng -D target_with_dexpreopt= -D target_arch=arm -D target_with_asan=false -D target_full_treble=true -s system/sepolicy/reqd_mask/security_classes system/sepolicy/reqd_mask/initial_sids system/sepolicy/reqd_mask/access_vectors system/sepolicy/reqd_mask/mls_macros system/sepolicy/reqd_mask/mls_decl system/sepolicy/reqd_mask/mls system/sepolicy/reqd_mask/reqd_mask.te system/sepolicy/reqd_mask/roles_decl system/sepolicy/reqd_mask/roles system/sepolicy/reqd_mask/users system/sepolicy/reqd_mask/initial_sid_contexts > out/target/product/generic/obj/FAKE/selinux_policy_intermediates/reqd_policy_mask.conf"
/bin/bash: line 1: 7142 Abort trap: 6 m4 -D mls_num_sens=1 -D mls_num_cats=1024 -D target_build_variant=eng -D target_with_dexpreopt= -D target_arch=arm -D target_with_asan=false -D target_full_treble=true -s system/sepolicy/reqd_mask/security_classes system/sepolicy/reqd_mask/initial_sids system/sepolicy/reqd_mask/access_vectors system/sepolicy/reqd_mask/mls_macros system/sepolicy/reqd_mask/mls_decl system/sepolicy/reqd_mask/mls system/sepolicy/reqd_mask/reqd_mask.te system/sepolicy/reqd_mask/roles_decl system/sepolicy/reqd_mask/roles system/sepolicy/reqd_mask/users system/sepolicy/reqd_mask/initial_sid_contexts > out/target/product/generic/obj/FAKE/selinux_policy_intermediates/reqd_policy_mask.conf
[ 0% 213/24512] build out/target/product/generic/obj/FAKE/selinux_policy_intermediates/plat_pub_policy.conf
FAILED: out/target/product/generic/obj/FAKE/selinux_policy_intermediates/plat_pub_policy.conf
原因:xcode 自带的m4在/usr/local/bin/m4。运行时 Abort trap: 6 。
办法:重新安装m4,命令为brew install m4 ,然后查看m4安装在哪 (which m4),如果是/usr/local/opt/m4/bin/m4,这个是可以运行的
You're missing the 'm4' tool, which we currently require to be installed on the host system.
以上是遇到的问题,也费了些时间解决,再次记录一下,免得其他人采坑。仅此。