Search code examples
androiddagger-2android-livedata

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


This happens for both Dagger generated files and for LiveData generated binding files.

I'll change branches and the generated file for the new Live Data layout or the generated MemberInjector for a new daggeer component will stick around even though those new components are actually on the other branch.

I'll do a Invalidate caches and restart as well as a clean build. But it doesn't work. I even tried manually deleting the files and they just got regenerated.

The only way I've found to fix it is to uninstall android studio and reinstall it.

My co-worker who uses a mac does not experience this problem.


Solution

  • 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