T
T
Tsuzukeru2021-03-17 16:28:56
Android
Tsuzukeru, 2021-03-17 16:28:56

Why is the Dagger component not created when writing the interface in Kotlin?

Practicing using Dagger 2 in Android.
Tagged one of the snippets with @Inject

class PreviewMediaFragment @Inject constructor() : Fragment() {
......
}


I create a component interface in Java
@Component
public interface AppComponent {
    public PreviewMediaFragment getFragment();
}


Everything works and now I can get the component in Application
class BaseApplication : Application() {

    lateinit var appcomponent: AppComponent

    override fun onCreate() {
        super.onCreate()
        appcomponent = DaggerAppComponent.create()
    }
}


But why if I create a component interface in Kotlin, then DaggerAppComponent is not generated?
I create the component like this:
@Component
interface AppComponent {
    fun getFragment():PreviewMediaFragment
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-03-17
@Tsuzukeru

To generate the code, you need to run kapt .
Not relevant to the question, but injecting a fragment constructor is a very bad idea. The fragment constructor should be empty, and therefore it is easier to call it by hand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question