Search code examples
androidbuild.gradledagger-hilt

2 files found with path 'META-INF/gradle/incremental.annotation.processors'. while using dagger hilt in android


`I am getting below error while building the app after adding dagger hilt dependency

2 files found with path 'META-INF/gradle/incremental.annotation.processors'. Adding a packagingOptions block may help, please refer to https://developer.android.com/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ResourcesPackagingOptions for more information

I added below plugins and dependency in app build.gradle.kts file

plugins
id("com.google.dagger.hilt.android")
kotlin("kapt")

dependencies
implementation("com.google.dagger:hilt-android:2.44")
implementation("com.google.dagger:hilt-compiler:2.44")

I have tried to change the below values in different ways.

excludes += "/META-INF/{AL2.0,LGPL2.1}" in packaging in gradle file.

I tried to change the value to excludes +="\*\*/\*" After changing this app is building successfully. But getting runtime exception. Thats Hilt BaseApplication not found.

BaseApplication extends Application

@HiltAndroidApp
class BaseApplication:Application()

Added this in Manifest file too android:name=".BaseApplication"


Solution

  • well try to use kapt instead of implementation for the hilt-compiler as follows :

    implementation("com.google.dagger:hilt-android:2.44")
    kapt("com.google.dagger:hilt-compiler:2.44")
    

    gonna work like charming (Y)

    reference : https://developer.android.com/training/dependency-injection/hilt-android