Build cache - sergei-lapin/pimp-my-gradle-recipes GitHub Wiki

Okay, let's tackle on some common build cache miss problems, then

Most of what you'll read next is targeting efficient usage of remote build cache

Sealed build

Try to avoid inconsistency of your build inputs as much as possible. For example, in case if you're, for any reason, inject your Git commit hash into your BuildConfig.java file then you invalidate your compileKotlin/compileJava tasks inputs each... err, commit. In case you can't neglect such nasty thing, then fallback to resources/assets, as they aren't considered as inputs of compilation, only for packaging.

Unify environment

As you're trying to get as much remote cache hits as possible — you have to consider environment, in which build is being run, as another input, hence it has to be the same in as many ways as possible for all machines executing these builds. This means:

  1. Same JDK (for CI builds, for IDE build, for shell builds) up to the last digit in version name (e.g. AdoptOpenJdk's jdk-11.0.10+9)
  2. Same android.jar revision (could be found at $ANDROID_HOME/platforms/PLATFORM_NAME/source.properties by Pkg.Revision key, where PLATFORM_NAME could be android-30, for example)
  3. No dynamic dependency declarations (like "group:dep:1.+")

Use Gradle doctor

This great plugin could help you a lot with identifying, for example, slow build cache connection speed