Last active
July 20, 2026 21:43
-
-
Save gilzoide/d611839a13ac55beffe06339c9a689a9 to your computer and use it in GitHub Desktop.
Gradle global ccache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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