Generated Files (Dagger, LiveData) show up on the wrong branch and get regenerated if I delete them

This might happen when using Gradle with the build cache enabled where it fails to recognize files no longer present after switching branches, so that it keeps recreating files that reference non-existant code.

Clearing the build cache directory (USER_HOME/.gradle/caches/build-cache-1) helps resolve the issue


I fixed this kind of problem (dagger created fabric for deleted class) by:

  1. Editing gradle.properties:

org.gradle.caching=false

  1. Building project

  2. Restoring gradle.properties:

org.gradle.caching=true

I also noticed that cleaning the project and deleting caches only doesn't work.


For myself, it was a combination of @David Medenjak's answer and a couple of other things.

  1. Delete the Gradle build cache: rm -rf ~/.gradle/caches/build-cache-1/
  2. Not sure if this step is required but delete your module's build/generated folder.
  3. Perform a rebuild of the project. Build > Rebuild Project