问题
I can't compile the code using a Model View Presenter(MVP) Hilt approach.
I get this error: /MotionPoC/app/build/generated/source/kapt/debug/com/aria/motionpoc/di/MotionApp_HiltComponents.java:145: error: [Dagger/MissingBinding] com.aria.motionpoc.coupon.MainActivity cannot be provided without an @Inject constructor or an @Provides-annotated method. This type supports members injection but cannot be implicitly provided.
The code itself:
MainActivity.kt
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), MainContract.View {
@Inject
lateinit var presenter: MainContract.Presenter
MainPresenter.kt
class MainPresenter @Inject constructor(
private val view: MainContract.View
): MainContract.Presenter {
override fun onViewCreated() {
view.showList()
}
}
MainModule.kt
@InstallIn(ActivityComponent::class)
@Module
abstract class MainModule {
@Binds
abstract fun bindActivity(view: MainActivity): MainContract.View
@Binds
abstract fun bindPresenter(impl: MainPresenter): MainContract.Presenter
}
MotionApp.kt
@HiltAndroidApp
open class MotionApp : Application()
来源:https://stackoverflow.com/questions/63306914/how-to-mvp-in-dagger-hilt