skip to content

A plain-Dagger Android build fails: how do you read a [Dagger/MissingBinding], [Dagger/IncompatiblyScopedBindings] or [Dagger/DependencyCycle] error back to its cause?

level: seniorimportance: should knowfreq 30%

answer

  1. the bracket names the validator
  2. trace runs from key to entry point
  3. reported on the component
  4. check which component holds the binding
  5. Provider or Lazy breaks a cycle

basics

~20 s

Read the bracketed check name, the reported key, then the trace from that key to the component entry point. A missing binding needs a provider in that component, a scope error a matching component scope, a cycle a Provider, a Lazy or a redesign.

solid answer

~50 s

Dagger names the failing check in brackets and reports it on the root component whose graph it was validating. For `[Dagger/MissingBinding]`, the first line says `X cannot be provided without an @Inject constructor or an @Provides-annotated method`; the `@Inject constructor` part disappears when X is an interface, an abstract class or a qualified key, which tells me I need a module binding. Below it the trace lists each `... is injected at` step down to the component method that pulled it in, and a note may say the key *is* provided in other components, meaning it is bound in the wrong component. `[Dagger/IncompatiblyScopedBindings]` lists scoped bindings reachable from a component that lacks that scope: move the binding to the component that owns the scope, or fix the annotation. `[Dagger/DependencyCycle]` prints the loop after `Found a dependency cycle:`; I break it with `Provider` or `Lazy`, or split the classes.

code

plaintext · 10 lines
plaintext
error: [Dagger/MissingBinding] PaymentGateway cannot be provided without an @Provides-annotated method.

    PaymentGateway is injected at
        [CheckoutComponent] CheckoutRepository(gateway)
    CheckoutRepository is injected at
        [CheckoutComponent] CheckoutPresenter(repository)
    CheckoutPresenter is injected at
        [CheckoutComponent] CheckoutActivity.presenter
    CheckoutActivity is injected at
        [CheckoutComponent] CheckoutComponent.inject(CheckoutActivity)

go deeper

for a junior

Recall that Dagger catches wiring mistakes at compile time and that the bracketed name, such as Dagger/MissingBinding, says which rule failed.

for a middle

Explain how to walk the trace from the missing key to the entry point and what the omitted @Inject-constructor phrase tells you.

for a senior

Diagnose fast: binding in the wrong component, scope reached from the wrong component, a cycle to break with Provider, and the KSP and 2.58 upgrade traps.

for a principal

Decide team defaults that surface errors early, such as full binding graph validation in CI and a single scope convention, against the build-time cost they add.

## How a Dagger error is laid out Dagger validates the **binding graph** of each root `@Component` during annotation processing. Each check is a validator with a name, and the name appears in brackets at the start of the message: `[Dagger/MissingBinding]`, `[Dagger/IncompatiblyScopedBindings]`, `[Dagger/DependencyCycle]`, `[Dagger/DuplicateBindings]` and others. Three habits make these messages fast to read: - **Start from the bracket.** It tells you which rule failed before you read any type names. - **Look at where it is reported.** Graph errors are attached to the **root component** being validated, not to the class that is missing something; the bracketed name in each trace line says which component or subcomponent resolved that request. In a multi-module build, that is often the app module even though the mistake sits in a feature module. - **Read the trace in order.** The first entry is the request nearest the problem; the last is the **entry point**, the provision or members-injection method on the component that pulled the chain in. Each line names the component in brackets where the request was resolved. ## `[Dagger/MissingBinding]`: no way to build a key The message reads `X cannot be provided without an @Inject constructor or an @Provides-annotated method.` Details carry information: - The phrase `an @Inject constructor or` is **omitted** when no `@Inject` constructor could ever satisfy the key: an interface, an abstract class, a qualified key such as `@Named("io") Executor`, or a generic type with wildcard type arguments. That points you straight at a missing `@Binds` or `@Provides` method. - The trace lines say `... is injected at` for constructor parameters and fields, and `... is requested at` for component provision methods. - A trailing note, `... is provided in the following other components`, means the binding exists, just not where the request is resolved. A parent never sees a subcomponent's bindings, and a component dependency exposes only its provision methods, so the usual fix is to move the module up a level or to expose a provision method. - In Kotlin, a multibound `Set<Foo>` or `Map<String, Foo>` may be seen as `Set<? extends Foo>`. The fix the Dagger guide gives is `@JvmSuppressWildcards` at the injection site. Since Dagger 2.58 the rewritten binding-graph logic is on by default (the `-Adagger.useBindingGraphFix` flag, which the Dagger docs say is removed in 2.61). One visible change: a module binding no longer silently **floats** from the component it is installed in down into a subcomponent to find a missing dependency, so code that compiled on older releases can now report a missing binding. The fix is to install the module in the component that actually has its dependencies. ## `[Dagger/IncompatiblyScopedBindings]`: a scope with no home A scoped binding must live in a component carrying that scope. The message takes one of two forms: 1. `AppComponent (unscoped) may not reference scoped bindings:` followed by the offending bindings. The component itself has no scope, but something it reaches does. 2. `AppComponent scoped with @Singleton may not reference bindings with different scopes:`, for example a `@ScreenScope` class reached from the application component. Fixes, in order of likelihood: request the binding from the subcomponent that owns that scope, move the module there, or correct the annotation on the class. Related scope errors cover a subcomponent that reuses an ancestor's scope, and `(unscoped) cannot depend on scoped components` for a component dependency. ## `[Dagger/DependencyCycle]`: a loop in direct requests The message begins `Found a dependency cycle:` and lists the bindings that form the loop, reported at the dependency closest to an entry point. Dagger cannot build either side first. A request for `Provider<T>`, `Lazy<T>` or `Provider<Lazy<T>>` breaks a cycle because it is resolved later, so changing one edge to a `Provider` makes it compile. Scoping the classes does not help. Often the honest fix is extracting the shared logic into a third class both depend on. ## A reading routine that scales | Error | First question | Usual fix | |---|---|---| | `MissingBinding` | Is it bound anywhere, and in which component? | Add `@Binds`/`@Provides`, move the module, expose a provision method | | `IncompatiblyScopedBindings` | Which component should own this scope? | Move the binding or request; fix the annotation | | `DependencyCycle` | Which edge can be deferred? | `Provider`/`Lazy` on one edge, or extract a class | - Pass `-Adagger.fullBindingGraphValidation=ERROR` (or `WARNING`) to also check modules and subcomponents that no root component currently uses; missing bindings are still reported only for graphs actually used. - After moving `dagger-compiler` from KAPT to KSP, a new class of error can appear: types generated by processors still running under KAPT are invisible to Dagger's KSP processor, reported as `unable to process ... could not be resolved`. Dagger's KSP support is stable as of 2.60.

  • A Dagger [Dagger/MissingBinding] error ends with a note that the key is provided in other components: what does that usually mean?
    The binding exists, but in a component the requesting component cannot see, typically a subcomponent or a sibling, since a parent never sees its children's bindings. Move the module up to the component where the request resolves, or request the object from inside the child instead.
  • After switching dagger-compiler from kapt to ksp on Dagger 2.60, Dagger says it was unable to process a class because a generated factory could not be resolved: why?
    Dagger's KSP processor cannot see types generated by processors still running under KAPT. If an `@Inject` constructor takes a class that another KAPT processor generates, that processor must move to KSP too, or the type must be replaced; the Dagger guide notes that an AutoFactory-generated factory, for example, can be replaced with Dagger's own `@AssistedInject`.
  • Why might a Dagger graph that compiled on an older release report a new missing binding after upgrading to 2.58 or later?
    The rewritten binding-graph logic, on by default since 2.58, stops a module's binding from floating from its installed component into a subcomponent to satisfy a dependency only available there. Install the module in the component that actually has every dependency the binding needs.

  • The error points at the class that is missing the binding, not the component.
  • Annotating both classes in a cycle with @Singleton fixes the cycle.
  • Missing bindings in an unused module always fail the build by default.
  • An unscoped component may freely reference @Singleton bindings it reaches.
  • A Kotlin Set<? extends Foo> missing binding means no @IntoSet contributions exist.

Assumes Dagger 2.60: the rewritten binding graph has been the default since 2.58, and Dagger's KSP processor is stable as of 2.60.