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分鐘