How to investigate why gradle build is using cached resource ids

Viewed 392

If have a gradle (5.4.1) project (plugin 3.4.1) with two flavors (main and other) using the same sourceSets. I've come across an issue when renaming a resource id (in a layout XML). Here are the observations:

  1. Android Studio 3.4.1 doesn't show any errors and works as expected, i.e. I can click through from kotlin code to the id in the layout xml.

  2. Rebuilding the main flavor also works as expected (no compilation errors).

  3. Rebuilding the other flavor gives a "unresolved reference" compilation error for the new ID. Gradle clean does not help. However, setting org.gradle.caching=false in the project-level gradle.properties does work (following Gradle sync, Clean, Rebuild). This explains why clean was not helping when caching was enabled.

On closer inspection of the R.java file, it seems to be using IDs from some rather old project state (presumably from the gradle cache stored in the user home directory). Now, I could just delete the gradle cache, but I'd rather find out why resource ID changes are not being processed properly. Whichever way Android Studio is running builds in the background, is working fine, just not when performing Build/Run etc.

All this investigation required a lot of trial and error: switching various gradle.properties settings one by one to see which one was leading to the problem, and I'm still no closer to finding the root cause of the problem.

What is the best approach to solving this type of problem, or is trial and error the only way?

0 Answers
Related