Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

Hilt build fails because Dagger finds no binding for a type

Your error

error: [Dagger/MissingBinding] com.example.data.AnalyticsService cannot be provided without an @Provides-annotated method.3 more lines it can show

Fix it fast

Most common cause, 1 of 4

An interface or library class has no @Binds or @Provides method

For an interface, write an abstract @Binds function inside an @InstallIn module that maps it to your implementation, and give the implementation an @Inject constructor.

Fix
@Module
@InstallIn(SingletonComponent::class)
abstract class AnalyticsModule {
    @Binds
    abstract fun bindAnalyticsService(impl: AnalyticsServiceImpl): AnalyticsService
}

class AnalyticsServiceImpl @Inject constructor() : AnalyticsService
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

[Dagger/MissingBinding] means the Hilt graph cannot create the type named in the error. Interfaces and library classes need an @Binds or @Provides method in a module installed in a component the requesting class can see. Read the Note lines under the error, then add or move the binding. Applies to Dagger and Hilt 2.60.1.

  • Applies to Dagger and Hilt 2.60.1, Hilt with KSP or kapt, Android Gradle builds on Java 17
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Build once and keep the whole error block, not only the first line. The type name, any annotation in front of it and the Note lines that follow decide which cause below is yours.

Run this first
./gradlew :app:assembleDebug 2>&1 | grep -A 30 "Dagger/MissingBinding"

Then find the line you see in this list and open its fix:

  1. 1An interface or library class has no @Binds or @Provides methodThe missing type is an interface, an abstract class or a class from a library, and no Note line follows the error
  2. 2The binding lives in a component the caller cannot reachA Note says the type is provided in the following other components, for example ActivityComponent
  3. 3Kotlin turned List<Plugin> into a wildcard typeThe missing type reads like java.util.List<? extends com.example.Plugin>, and the output suggests @JvmSuppressWildcards
  4. 4A qualifier is on one side of the binding onlyThe type in the error starts with an annotation such as @javax.inject.Named("auth"), or your @Provides method has one and the error shows the bare type

What does the error look like?

  • error: [Dagger/MissingBinding] com.example.data.AnalyticsService cannot be provided without an @Provides-annotated method.
  • cannot be provided without an @Inject constructor or an @Provides-annotated method.
  • Note: com.example.data.AnalyticsService is provided in the following other components:
  • Note: A similar binding is provided in the following other components:

Cause 1 of 4

An interface or library class has no @Binds or @Provides method

You seeThe missing type is an interface, an abstract class or a class from a library, and no Note line follows the error

Check

Dagger/MissingBinding appears here because Hilt can only build a class on its own when that class has an @Inject constructor. An interface has no constructor at all, and you cannot add the annotation to a class shipped in a library, so a module has to tell Hilt what to return.

Check
grep -rn "AnalyticsService" app/src/main --include=*.kt | grep -E "@Binds|@Provides"

Fix

For an interface, write an abstract @Binds function inside an @InstallIn module that maps it to your implementation, and give the implementation an @Inject constructor. For a library class such as Retrofit or OkHttpClient, add an @Provides function that builds and returns it.

Fix
@Module
@InstallIn(SingletonComponent::class)
abstract class AnalyticsModule {
    @Binds
    abstract fun bindAnalyticsService(impl: AnalyticsServiceImpl): AnalyticsService
}

class AnalyticsServiceImpl @Inject constructor() : AnalyticsService

Verify

The build passes and the generated Hilt code compiles without a MissingBinding line.

Verify
./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 4

The binding lives in a component the caller cannot reach

You seeA Note says the type is provided in the following other components, for example ActivityComponent

Check

When the error carries that Note, Dagger did find a binding for the exact type, but in a different component. A module's bindings are only visible to that component and to the components below it, so a @Singleton class cannot use something installed in ActivityComponent.

Check
grep -rn -B2 "object AnalyticsModule\|class AnalyticsModule" app/src/main --include=*.kt

Fix

Change the module's @InstallIn to a component that sits above every class that injects the type, usually SingletonComponent for app-wide services. If the binding has a scope annotation, change it to the scope of the new component, since a scope must match the component it is installed in.

Fix
@Module
@InstallIn(SingletonComponent::class)   // was ActivityComponent::class
object AnalyticsModule {
    @Provides
    @Singleton                            // was @ActivityScoped
    fun provideAnalytics(): AnalyticsService = AnalyticsServiceImpl()
}

Verify

The Note about other components is gone and the build finishes.

Verify
./gradlew :app:assembleDebug

Confirmed by dagger.dev

Did this fix it?

Cause 3 of 4

Kotlin turned List<Plugin> into a wildcard type

You seeThe missing type reads like java.util.List<? extends com.example.Plugin>, and the output suggests @JvmSuppressWildcards

Check

MissingBinding on a generic type in Kotlin is often a wildcard mismatch. The Kotlin compiler writes some generic parameters as Java wildcards (? extends), so the type Dagger looks for no longer equals the one your module returns. Dagger then prints a similar-binding Note together with a hint about @JvmSuppressWildcards.

Check
./gradlew :app:assembleDebug 2>&1 | grep -B2 -A6 "similar binding"

Fix

Put @JvmSuppressWildcards on the generic type at the injection site, or on the whole constructor or class, so Kotlin keeps the exact type the module provides.

Fix
class PluginRunner @Inject constructor(
    private val plugins: List<@JvmSuppressWildcards Plugin>
)

Verify

The type in the build output no longer shows ? extends and the binding resolves.

Verify
./gradlew :app:assembleDebug

Confirmed by kotlinlang.org

Did this fix it?

Cause 4 of 4

A qualifier is on one side of the binding only

You seeThe type in the error starts with an annotation such as @javax.inject.Named("auth"), or your @Provides method has one and the error shows the bare type

Check

A qualifier is part of the key Dagger matches on. A @Provides method marked @AuthClient OkHttpClient does not satisfy a constructor parameter that asks for a plain OkHttpClient, and the reverse fails the same way, even though the class is identical.

Check
grep -rn "@Named\|@Qualifier" app/src/main --include=*.kt

Fix

Put the same qualifier on the injection site as on the @Provides or @Binds method, or remove it from both. On a Kotlin field, annotate the lateinit var with the qualifier next to @Inject.

Fix
class ApiRepository @Inject constructor(
    @AuthInterceptorOkHttpClient private val client: OkHttpClient
)

Verify

The qualified type now resolves and the build completes.

Verify
./gradlew :app:assembleDebug

Confirmed by dagger.dev

Did this fix it?

How do I stop it coming back?

  • Give every interface a @Binds entry in the same commit that adds the interface, and keep those modules in one di package so a reviewer can spot a gap.
  • Install app-wide services in SingletonComponent by default and narrow the component only when a shorter lifetime is the goal.
  • Declare qualifiers once as annotation classes rather than free-text @Named strings, so a misspelt name fails to compile instead of quietly creating a second key.
  • Run assembleDebug in CI on every pull request, because Dagger checks how bindings fit together only when it generates the component, not when a single module compiles.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: QistLock, Nuclear Home Video.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.