Using ccache to build Android

Once when files related to Makefile (*.mk) is changed, it is necessary to do “make clean; make”.
This is time-consuming work. It can reduce time using ccache. It is very easy to use ccache to build Android.
(Japanese version)

What is ccache?

See this page.

When the first compiling, ccache preserves the compilation result in another directory. And, it is checked whether a content and an optional compilation of last time and the file are corresponding at the following compilation, and uses the content preserved instead of actually compiling when agreeing.

It is C/C++/Objective-C/Objective-C++ that ccache supports, and is not supported Java.

Speed up effect will come after the second time build.

And remember that the large amount of disk is consumed to preserve the compilation result.

Using ccache to build Android

It is very easy to use ccache to build Android. Only add “USE_CCACHE=1” to environment variables or make variables.It is not necessary to install it newly because the ccache command is already in the prebuilt directory.

One line is added to, which is used at previous post.

$ cat
export TARGET_ARCH_VARIANT=armv7-a-neon
export TARGET_CPU_SMP=true
export WITH_JIT=true
export JS_ENGINE=v8
export USE_CCACHE=1
time make -j8 showcommands > make.log 2>&1 

My build machine is Ubuntu 10.04, CPU: Intel Core i7 950 @3.07GHz, memory 12GB.

The first time build

$ rm -rf out
$ ./ 
real 14m2.447s
user 111m48.370s
sys 6m38.000s

The second time build

$ rm -rf out$ ./
real 8m45.569s
user 70m45.080s
sys 4m27.270s

Look at this! Build time is reduced from 14min. to 8min.45sec. Wow.

Makefile of Android

USE_CCACHE has been treated in the following points.


ifneq ($(USE_CCACHE),)
  ccache := prebuilt/$(HOST_PREBUILT_TAG)/ccache/ccache
  # prepend ccache if necessary
  ifneq ($(ccache),$(firstword $($(combo_target)CC)))
    $(combo_target)CC := $(ccache) $($(combo_target)CC)
  ifneq ($(ccache),$(firstword $($(combo_target)CXX)))
    $(combo_target)CXX := $(ccache) $($(combo_target)CXX)
  ccache =

CC and CXX have been replaced. It doesn’t influence the build of java.

Related pages

Quick hack to run Android 2.3(Gingerbread) on KZM-A9-Dual board


About tetsu_koba

This entry was posted in Android. Bookmark the permalink.

3 Responses to Using ccache to build Android

  1. Pingback: Comparing 3 JDKs by Android build time « Koba's blog

  2. Pingback: Using ccache to build Android(2) « Koba's blog

  3. Pingback: Using ccache to build Android | Android Development

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s