Dagger: Duplicate generated MembersInjector classes for abstract DaggerAppCompatActivity subclass with multiple Gradle modules

Created on 18 Mar 2018  路  3Comments  路  Source: google/dagger

Dagger 2.15

Given a Gradle project with 4 Gradle modules, A, B, C, D, and DAG-like module dependencies:
A depends on B and C.
B and C depend on D.

Module D contains an abstract class X (with no @Inject) that extends DaggerAppCompatActivity.
Module B contains concrete class Y, module C contains concrete class Z. Y and Z each extend X. (Y and Z have @Injects.)

Building module A generates duplicate classes X_MembersInjector, one in module B, and another in module C. The Android D8 Dexer trips over this and fails. I don't blame it.

Most helpful comment

It seems to be duplicate of #1029 (#955 and #814 )

New D8 Dexer Compiler is reporting:

Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: X_MembersInjector

In my case issue only happens when compiling application for device below SDK 21. From above linked issues only solution is to add any (unused) injection to X abstract class, then Dagger will generate MembersInjector in correct module.

All 3 comments

To address this issue I would expect to either see X_MembersInjector getting generated in module D, or no X_MembersInjector getting generated at all, and instead just seeing Y_MembersInjector and Z_MembersInjector.

I don't see an actual use of X_MembersInjector in the project, so it appears to be generated unnecessarily.

It seems to be duplicate of #1029 (#955 and #814 )

New D8 Dexer Compiler is reporting:

Caused by: com.android.tools.r8.errors.CompilationError: Program type already present: X_MembersInjector

In my case issue only happens when compiling application for device below SDK 21. From above linked issues only solution is to add any (unused) injection to X abstract class, then Dagger will generate MembersInjector in correct module.

I am going to close this. I was battling many build issues at the time, and it was difficult to keep the different root causes apart. As @pbednarz points out, this is not a particularly valid issue. I was able to work around the problem with dummy method injection.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pedrovarela86 picture pedrovarela86  路  3Comments

vorburger picture vorburger  路  4Comments

JakeWharton picture JakeWharton  路  3Comments

SteinerOk picture SteinerOk  路  3Comments

sagarwaghmare07 picture sagarwaghmare07  路  3Comments