anvil
anvil copied to clipboard
@Component.Factory types must be nested within a @Component
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 ?
I too have the same problem, and with @Component.Builder
I have the same issue building with ksp, @mustafatatarhan0 are you building with ksp as well?
@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 https://github.com/square/anvil/pull/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!
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