Skip to content

Instantly share code, notes, and snippets.

@gilzoide
Last active July 20, 2026 21:43
Show Gist options
  • Select an option

  • Save gilzoide/d611839a13ac55beffe06339c9a689a9 to your computer and use it in GitHub Desktop.

Select an option

Save gilzoide/d611839a13ac55beffe06339c9a689a9 to your computer and use it in GitHub Desktop.
Gradle global ccache
// For every Gradle project that uses `com.android.application` or `com.android.library`,
// setup both ndk-build and CMake to use `ccache` as the compiler launcher if `ccache` is
// found in the user's $PATH environment
//
// Add to your project's build.gradle or install globally in your init.gradle: https://docs.gradle.org/current/userguide/init_scripts.html
gradle.projectsLoaded {
rootProject.allprojects {
afterEvaluate { project ->
if (project.plugins.hasPlugin("com.android.application") || project.plugins.hasPlugin("com.android.library")) {
def ccache = project.providers.exec {
commandLine "which", "ccache"
ignoreExitValue = true
}.standardOutput.asText.getOrElse("").trim()
if (ccache) {
project.android.defaultConfig.externalNativeBuild {
ndkBuild.arguments "NDK_CCACHE=$ccache"
cmake.arguments "-DCMAKE_C_COMPILER_LAUNCHER=$ccache",
"-DCMAKE_CXX_COMPILER_LAUNCHER=$ccache"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment