How to Enable ccache in AOSP 15

Starting with AOSP 15, the build system (Soong) enforces stricter control over which tools can be used during the build process. As a result, tools like ccache are blocked by default, even if USE_CCACHE=1 is set.

If you wish to re-enable ccache for local development, you can do so with a simple patch — but be aware that this setup diverges from AOSP defaults and should be applied with caution, especially if you’re building in shared or remote environments.


  1. Patch Soong to Allow Ccache

Edit the file:

build/soong/ui/build/paths/config.go

Inside the Configuration map, add this line:

"ccache":      Allowed,

For example:

var Configuration = map[string]PathConfig{
    "bash":        Allowed,
    "diff":        Allowed,
    "git":         Allowed,
    "ccache":      Allowed,
    ...

  1. Enable Ccache in Your Environment

Add the following to your shell or build script:

export USE_CCACHE=1
export CCACHE_DIR=/ccache
export CCACHE_EXEC=$(which ccache)
ccache -M 100G   # Optional: set maximum cache size

Place these lines in .bashrc, .zshrc, or build/envsetup.sh if needed.


  1. Build and Verify Ccache Is Working

Reset ccache stats:

ccache -z

Build a target:

source build/envsetup.sh
lunch aosp_cf_x86_64_phone-trunk_staging-userdebug
m

Check the cache stats:

ccache -s

You should see output like:

Cacheable calls:   20001 / 20247 (98.79%)
  Hits:             4681 / 20001 (23.40%)
    Direct:         3532 /  4681 (75.45%)
    Preprocessed:   1149 /  4681 (24.55%)
  Misses:          15320 / 20001 (76.60%)
Uncacheable calls:   246 / 20247 ( 1.21%)
Local storage:
  Cache size (GB):   2.3 /  60.0 ( 3.80%)
  Hits:             4681 / 20001 (23.40%)
  Misses:          15320 / 20001 (76.60%)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top