需求
android 4, 其sdk的git工程大小为9G,
android sdk编译时间
- make clean后的编译35分钟;
- debug与user版本交叉编译时需要先make clean,否则编译出来的镜像会启动不了,一次编译需要35分钟;
- 已经编译过,不make clean前提下再次编译时间8分钟。
需求是缩短编译时间,方法是开启ccache功能
方法
编译前执行以下命令
# 开启
export USE_CCACHE=1
# 设置缓存目录,可自行指定
export CCACHE_DIR=~/.ccache
# 限制缓存大小,可酌情修改,硬盘大就设置大些,比如20G或50G
prebuilts/misc/linux-x86/ccache/ccache -M 10G
# 注意如果是android10及以上,是不存在prebuilts/misc/linux-x86/ccache/ccache的,需要sudo apt-get install ccache安装,然后再多加个环境变量CCACHE_EXEC
export CCACHE_EXEC=/usr/bin/ccache
ccache -M 10G
查看是否工作,在编译的同时,执行下命令
watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
或者10以上为 watch -n1 -d ccache -s
输出如下,可以看到cache size那里说明了当前cache的大小,在编译过程中它会不断增加的:
cache directory /home/x/.ccache
primary config /home/x/.ccache/ccache.conf
secondary config (readonly) /etc/ccache.conf
stats zero time Wed Sep 1 07:59:53 2021
cache hit (direct) 0
cache hit (preprocessed) 0
cache miss 25534
cache hit rate 0.00 %
called for preprocessing 20
cleanups performed 0
files in cache 77113
cache size 4.0 GB
max cache size 50.0 GB
优点
- make clean后编译时间为8到13分钟,减少20多分钟;
- debug与user版本交叉编译也可使用缓存功能,编译时间8到13分钟;
- 已经编译过的,不make clean前提下再次编译无法使用到ccache缓存功能,暂未研究
作者:帅得不敢出门