question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Hilt] Dynamic Feature R8 isMinifyEnabled = true, showing error: is defined multiple times

See original GitHub issue

Version

Hilt: 2.28.3-alpha in :base module Using vanilla dagger in :dynamic-feature module AGP: 4.0.1 GWP: 6.5.1 Kotlin: 1.3.72

Problems

Context

R8 isMinifyEnabled = false, succeed to build & runs, otherwise it fails as described in the title

Question

  1. Is it currently not supported to define same dependency class in multiple class and used injected across dynamic feature module?
  2. Is it R8 restriction due to multiple class defined? and how to solve that?

Our usecase:

:data is a java only module

class MapperA @Inject constructor()

class AuthRepositoryImpl @Inject constructor(
    private val mapper: MapperA
) : AuthRepository

class AccountRepositoryImpl @Inject constructor(
    private val mapper: MapperA
) : AccountRepository

:dynamic-feature:auth module

@DisableInstallInCheck
@Module
interface AuthModule {
    @get:[Binds]
    val AuthRepoistoryImpl.repository: AuthRepository
}

:dynamic-feature:account module

@DisableInstallInCheck
@Module
interface AccountModule {
    @get:[Binds]
    val AccountRepoistoryImpl.repository: AccountRepository
}

I’ve tried to implement @Qualifers to annotate it as different dependencies but doesn’t work either, see here #2074

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Chang-Ericcommented, Sep 23, 2020

Since it is MapperA_Factory that is being duplicated, my guess as to what is going on here is that you aren’t running the Dagger processor over the MapperA class and are pulling it into two different Dagger components.

Factory generation for @Inject classes can happen in two places: on the class itself if you run the Dagger processor (preferred) or lazily when used by the Dagger component. The problem with the second case is that if you have two Dagger components built separately we’ll generate the same factory twice. (There’s also a separate problem that generating it at the component can reduce build parallelism if you have a lot of factory classes to generate too, but that isn’t your direct issue right now).

0reactions
mochadwicommented, Sep 26, 2020

I don’t think it is in the documentation (not sure there is a great place to put it right now), but you should have gotten a build warning about it at least https://github.com/google/dagger/blob/master/java/dagger/internal/codegen/validation/InjectBindingRegistryImpl.java#L130

Nice! Closing this issue now~

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic feature modules couldn't generate correctly with AGP ...
So it fails minifyReleaseWithR8 task in our app in release build. Pls check below stack trace: DataBindingCallbacks.class is a class we defined ......
Read more >
minifyWithR8 issue with Dynamic feature module, release build
I am working on a dynamic feature module for the first time. ... ListenableFuture is defined multiple times: ... com.android.tools.r8.
Read more >
R8 Minify: Type Defined Multiple Times - ADocLib
I'm getting this error when I try to add an implementation to my app's gradle file for Contentful Type com.google.gson.ExclusionStrategy is defined multiple....
Read more >
Dependency injection with Hilt | Android Developers
To learn more about which lifecycle callback an Android class gets injected in, see Component lifetimes. Define Hilt bindings. To perform field injection,...
Read more >
The Ultimate Dagger-Hilt Guide (Dependency Injection)
Dependency injection is a core concept of software development. In this video, I'll show you how you can apply DI in an Android...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found