来源:官方文档:

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


更多相关文章

  1. FileUtil:文件处理工具类
  2. TextView使用指定的TTF字库
  3. 网络获取图片实现无线自动轮播
  4. android 获取缓存文件的地址
  5. ubuntu 12.10 上 android 编译环境搭建
  6. 真正实现TextView跑马灯效果
  7. streamingAssetsPath 内文件读取
  8. Android(安卓)apk反编译记录
  9. Android(安卓)WebView缓存机制详解

随机推荐

  1. Android工具箱APP源码分享:“一个工具箱”
  2. Android知识简单测试题
  3. Android中View的滑动
  4. Android 使用ORMLite打造万能泛型Dao简化
  5. 1.Android(了解Android王国)
  6. Service和Activity通讯的3种常用方式示例
  7. android tab和listiew
  8. Android(安卓)自动检测版本并升级
  9. android中资源整理
  10. Android(安卓)架构组件(一)——Lifecycle