How to Enable ccache in AOSP 15

ccache is a powerful compiler cache that speeds up Android builds by avoiding redundant compilation. AOSP 15 fully supports it when configured correctly — no changes to the build system are necessary.

This guide walks you through enabling ccache in a reliable and portable way.


  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. Improve Cache Sharing Across Directories (Optional)

If you build the same source code from different paths (e.g. different branches or clones), you can make ccache ignore those differences in its hashes:

Configure via file:

# ~/.ccache/ccache.conf
hash_dir = false

Or configure via environment:

export CCACHE_NOHASHDIR=1

To confirm it’s active:

ccache -p | grep hash_dir

Expected output:

hash_dir = false

  1. Build and Verify Ccache Is Working

Reset ccache stats:

ccache -z

Build a target:

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

Check the cache stats:

ccache -s

You should see output like:

Cacheable calls:   73517 / 78098 (94.13%)
  Hits:            73517 / 73517 (100.0%)
    Direct:        73492 / 73517 (99.97%)
    Preprocessed:     25 / 73517 ( 0.03%)
  Misses:              0 / 73517 ( 0.00%)
Uncacheable calls:  4581 / 78098 ( 5.87%)
Local storage:
  Cache size (GB):  37.8 /  60.0 (62.96%)
  Hits:            73517 / 73517 (100.0%)
  Misses:              0 / 73517 ( 0.00%)

Leave a Comment

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

Scroll to Top