Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate bindings created for multiple @MergeComponents of the same scope #123

Closed
RBusarow opened this issue Aug 4, 2021 · 1 comment · Fixed by #124 or #127
Closed

Duplicate bindings created for multiple @MergeComponents of the same scope #123

RBusarow opened this issue Aug 4, 2021 · 1 comment · Fixed by #124 or #127
Labels
bug Something isn't working

Comments

@RBusarow
Copy link
Owner

RBusarow commented Aug 4, 2021

There must be two components in a classpath. It doesn't matter if they're in the same Gradle module, or the same package, or if one of those components is in test source.

My specific issue was for creating duplicate bindings for TestAppComponent when I'd already created them for AppComponent in the same (Gradle) module.

Example:

src/java/main/com/example/app/Component.kt

package com.example.app

@MergeComponent(AppScope::class)
interface Component

src/java/test/com/example/app/TestComponent.kt

package com.example.app

@MergeComponent(AppScope::class)
interface TestComponent

Tangle just looked for the @MergeComponent annotation, and creates essentially the same code for both:

@Module
@ContributesTo(Unit::class)
public interface Unit_Tangle_FragmentFactory_Module {
  @Multibinds
  public fun bindProviderMap(): Map<Class<out androidx.fragment.app.Fragment>, @JvmSuppressWildcards
      Fragment>

  @Multibinds
  @TangleFragmentProviderMap
  public fun bindTangleProviderMap(): Map<Class<out androidx.fragment.app.Fragment>,
      @JvmSuppressWildcards Fragment>

  public companion object {
    @Provides
    public
        fun provideTangleFragmentFactory(providerMap: Map<Class<out androidx.fragment.app.Fragment>,
        @JvmSuppressWildcards Provider<@JvmSuppressWildcards Fragment>>, @TangleFragmentProviderMap
        tangleProviderMap: Map<Class<out androidx.fragment.app.Fragment>, @JvmSuppressWildcards
        Provider<@JvmSuppressWildcards Fragment>>): TangleFragmentFactory =
        TangleFragmentFactory(providerMap, tangleProviderMap)
  }
}

And that provideTangleFragmentFactory function creates issues. There's a similar problem with the Subcomponent factory bindings created for ViewModels.

If this was just vanilla Dagger, the fix would be to make the generated module internal, since it's in the same package as the component and only needs to be visible right there. However, Anvil doesn't support internal modifiers.

@RBusarow RBusarow added the bug Something isn't working label Aug 4, 2021
RBusarow added a commit that referenced this issue Aug 4, 2021
@kodiakhq kodiakhq bot closed this as completed in #124 Aug 4, 2021
kodiakhq bot pushed a commit that referenced this issue Aug 4, 2021
@RBusarow RBusarow reopened this Aug 4, 2021
@RBusarow
Copy link
Owner Author

RBusarow commented Aug 4, 2021

Still broken for ViewModels. I missed it thanks to a build cache issue.

RBusarow added a commit that referenced this issue Aug 4, 2021
RBusarow added a commit that referenced this issue Aug 4, 2021
* fix ViewModel duplicate bindings
fixes #123 for real

* api dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant