强力提高 android 4 编译效率(c,c++部分)

来源:官方文档:

http://source.android.com/source/initializing.html#ccache

Setting up ccache

You can optionally tell the build to use the ccache compilation tool. Ccache acts as a compiler cache that can be used to speed-up rebuilds. This works very well if you do "make clean" often, or if you frequently switch between different build products.

Put the following in your .bashrc or equivalent.

export USE_CCACHE=1

By default the cache will be stored in ~/.ccache. If your home directory is on NFS or some other non-local filesystem, you will want to specify the directory in your .bashrc as well.

export CCACHE_DIR=<path-to-your-cache-directory>

The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

When building Ice Cream Sandwich (4.0.x) or older, ccache is in a different location:

prebuilt/linux-x86/ccache/ccache -M 50G

This setting is stored in the CCACHE_DIR and is persistent.


------------------------------------------------

原理:

ccache的使用方式,可以加速我们c与c++的编译速度原理就是中间文件的一个缓存,是同一个.o文件的话就省去再次编译的速度。

介于android中c与c++文件数量能占到刚不到一半,所以这个速度还是能省下很多的。


----------------------------------------------

配置:

1在环境变量里添加:

export USE_CCACHE=1
export CCACHE_DIR=/HDD/.ccache

环境变量有四个位置添加都有效,我习惯添加到全局用户环境变量配置文件:sudo gedit /etc/profile,

第一个是标志,android编译会检测这个

第二个是缓存路径,默认是~/.ccache)

2随便找一个android工程(可能需要2.3以上),设置缓存的大小(注意每执行一次这个,缓存路径会被初始化一次,所以执行一次就好);

prebuilt/linux-x86/ccache/ccache -M 50G

第一次编译一个工程,会缓存工程.o文件,

第二次提升效果明显

ccache缓存的调用情况执行下面命令监视

$watch -n1 -d prebuilt/linux-x86/ccache/ccache -s

---------------------------------------------------------------------------

真实测试:

工程android 4.0.4

第一次编译:make -j8      36分钟左右

修改了frameworks的一个资源文件;

再次编译:make clean;make -j8     18分钟 

缓存文件夹ccache大小为3.3g


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值