Excessive Auto-Generated Files and Cleanup Process in Hilt-Integrated
In your Android project, you have been using Hilt successfully for dependency injection. However, over time, I've noticed that an excessive number of auto-generated files related to Hilt have accumulated in your project directory. These files clutter your project structure, making it difficult to manage and maintain.
We would greatly appreciate your guidance on how to effectively remove all unnecessary auto-generated files related to Hilt from our project and prevent them from reappearing. Additionally, any insights into why these files are persisting after removing Hilt dependencies would be valuable.
Solution: Clean and Remove Auto-Generated Hilt Files Step 1: Remove Hilt Dependencies In your build.gradle (app-level):
// Remove these if present implementation "com.google.dagger:hilt-android:X.X.X" kapt "com.google.dagger:hilt-compiler:X.X.X" Also remove:
apply plugin: 'dagger.hilt.android.plugin' And in build.gradle (project-level):
// Remove classpath if added classpath "com.google.dagger:hilt-android-gradle-plugin:X.X.X" Step 2: Invalidate Cache & Restart In Android Studio:
Go to File > Invalidate Caches / Restart
Select "Invalidate and Restart"
This clears lingering compiler cache that may retain Hilt files.
Step 3: Clean Build Artifacts Run in terminal:
./gradlew clean Manually delete:
/build/
/build/generated/
.kapt/
.hilt/
.dagger/ (if present)
Step 4: Full Rebuild Without Hilt After cleaning, rebuild your project without Hilt:
./gradlew assembleDebug Why Hilt Files Persist Hilt uses annotation processors (kapt) which generate files during the build process.
Even if you remove Hilt from Gradle, those files won’t delete themselves — they sit in /build/generated/, .kapt/, etc.
Without a clean or cache invalidation, Studio may reference outdated generated code.
How to Prevent in Future Use .gitignore to exclude:
/build/ /.kapt/ /.hilt/ /.dagger/ Regularly run:
./gradlew clean Don’t commit or manually copy generated sources — treat them as ephemeral.