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.

Compile error while trying to replace dependency in androidTest

See original GitHub issue

Halo!

I’ve had a build failure while trying to write a sample project with anvil.

While I used only one AppScope dependencies everything was alright, but when I tried to use ActivityScope for screen subcomponent, I’ve got an error in test component, which was used to test anvil dependency replacement feature:

error: Found conflicting entry point declarations. Getter methods on the component with the same name and signature must be for the same binding key since the generated component can only implement the method once. Found:
public abstract interface TestAppComponent extends com.example.di_demo.AppComponent, com.example.auth_api.AuthDependencies, com.example.auth_impl.di.AuthScreenMergeComponent.ParentComponent, anvil.component.com.example.di_demo.testappcomponent.AuthScreenMergeComponentA.ParentComponent {
                ^
      @org.jetbrains.annotations.NotNull anvil.component.com.example.di_demo.appcomponent.AuthScreenMergeComponentA.SubcomponentFactory anvil.component.com.example.di_demo.appcomponent.AuthScreenMergeComponentA.ParentComponent.authScreenMergeComponentFactory()
      @org.jetbrains.annotations.NotNull @Override anvil.component.com.example.di_demo.testappcomponent.AuthScreenMergeComponentA.SubcomponentFactory anvil.component.com.example.di_demo.testappcomponent.AuthScreenMergeComponentA.ParentComponent.authScreenMergeComponentFactory()

Code compiles just okay in ordinary scenario, and fails only in androidTest environment.

Sample project can be found here: https://github.com/midery/di_demo/tree/minimum-reproducible-issue

AppComponent

TestAppComponent

AuthScreenMergeComponent

I will be grateful for any help regarding this issue.

Also, if this project structure is messed up, I would also appreciate any hint on screen component dependencies organization.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vRallevcommented, Sep 15, 2022

Here’s another helpful sample: https://github.com/gpeal/Anvil-Sample

1reaction
JoelWilcoxcommented, Sep 12, 2022

👋 thanks for providing the project! It looks like the issue is that you’re still referencing your main Application class and component in the test code. This means that Dagger/Anvil will attempt to compile the main graph in addition to the test graph since the test component and application are extending their main source counterparts. Making the following changes should get things working:

TestApp.kt:

class TestApp : Application(), ComponentHolder<TestAppComponent> {

    override lateinit var component: TestAppComponent

    override fun onCreate() {
        super.onCreate()
        component = DaggerTestAppComponent.factory().create(this)
    }
}

TestAppComponent.kt:

@SingleIn(AppScope::class)
@MergeComponent(
    AppScope::class,
)
interface TestAppComponent {

    @Component.Factory
    interface Factory {
        fun create(
            @BindsInstance application: Application
        ): TestAppComponent
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

testing - Dependency conflict error in my Android app which ...
To resolve the conflict you first need to figure out the two versions that are conflicting. If you aren't already using the Android...
Read more >
Hilt, androidTest build failed in versions >= 2.40.4 · Issue #3162
ComponentProcessor was unable to process 'dagger.hilt.android.internal.testing.root.Default_HiltComponents.SingletonC' because not all of its ...
Read more >
Add build dependencies - Android Developers
Learn how to add build dependencies using the Gradle build system in Android Studio.
Read more >
Using kapt | Kotlin
If you previously used the Android support for annotation processors, replace usages of the annotationProcessor configuration with kapt .
Read more >
Improve the Performance of Gradle Builds
If the change improved build times, make it permanent. If you don't see an improvement, remove the change and try another.
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