Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 671
Dan Anderson Avatar asked May 31 '19 23:05

Dan Anderson


3 Answers

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

like image 68
David Medenjak Avatar answered Nov 16 '22 07:11

David Medenjak


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
like image 27
StuStirling Avatar answered Nov 16 '22 06:11

StuStirling


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.

like image 5
Inliner Avatar answered Nov 16 '22 07:11

Inliner