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

@Component.Factory types must be nested within a @Component #790

Open
mustafatatarhan0 opened this issue Nov 21, 2023 · 4 comments
Open

Comments

@mustafatatarhan0
Copy link

mustafatatarhan0 commented Nov 21, 2023

AppComponent.kt:

@SingleIn(AppScope::class)
@MergeComponent(AppScope::class)
interface AppComponent : NodeFactoriesBindings {

    @Component.Factory
    interface Factory {
        fun create(
            @ApplicationContext @BindsInstance
            context: Context,
        ): AppComponent
    }
}

When anvil generate AppComponent.java, error comes:
error: @Component.Factory types must be nested within a @Component

What is the reason of this error ? How can I fix this ?

@b-reetz
Copy link

b-reetz commented Feb 13, 2024

I too have the same problem, and with @Component.Builder

@kevinguitar
Copy link

I have the same issue building with ksp, @mustafatatarhan0 are you building with ksp as well?

@jamesonwilliams
Copy link

@kevinguitar I ran into this while trying to use Dagger KSP, too, yeah. I think in short, the deal is that Anvil doesn't currently support Dagger KSP.

However, this draft PR #1001 went up 2 days ago, which is directly about getting the @Component.Factory and @Component.Builder to work under an @MergeComponent. Very exciting stuff!

@itsandreramon
Copy link

itsandreramon commented Jul 12, 2024

Edit: I just found out that component merging will not work regardless of K2 KAPT or KSP and needs to use the workarounds described in the link

I got this error even with K2 Kapt enabled:

@Subcomponent.Factory types must be nested within a @Subcomponent
    public static abstract interface Factory {
                           ^

The component in question looks like this:

@SingleIn(UserScope::class)
@MergeSubcomponent(UserScope::class)
interface UserComponent {

    @Subcomponent.Factory
    interface Factory {
        fun create(
            @BindsInstance userSession: UserSession,
            @BindsInstance userCoroutineScope: UserCoroutineScope,
        ): UserComponent
    }

    fun inject(activity: MainActivity)
}

I am using 2.5.0-beta09 with Kotlin 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants