Hilt not working with AbstractComposeView for Jepack Compose
See original GitHub issueI am using DaggerHilt for dependency injection. In my AbstractComposeView, I need to access the ViewModel in a Composable function. To do that I have to annotate my AbstractComposeView with AndroidEntryPoint, since my Composable is part of the AbstractComposeView (which is being used in a Service with AndroidEntryPoint). but I am getting this error.
error: [Hilt] The base class, 'androidx.compose.ui.platform.AbstractComposeView', of the @AndroidEntryPoint, 'com.qwillio.vendi.keyboard.presentation.KeyboardView', contains a constructor with default parameters. This is currently not supported by the Gradle plugin. Either specify the base class as described at https://dagger.dev/hilt/gradle-setup#why-use-the-plugin or remove the default value declaration. [Hilt] Processing did not complete. See error above for details. [Hilt]
This is my AbstractComposeView,
@AndroidEntryPoint
class KeyboardView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AbstractComposeView(context, attrs, defStyleAttr) {
private var keyboardActionListener: OnKeyboardActionListener? = null
fun setOnKeyboardActionListener(keyboardActionListener: OnKeyboardActionListener) {
this.keyboardActionListener = keyboardActionListener
}
@Composable
override fun Content() {
Vendiboard {
keyboardActionListener?.onKeyboardAction(it)
}
}
}
build.gradle
implementation "com.google.dagger:hilt-android:2.40.5"
kapt "com.google.dagger:hilt-android-compiler:2.40.5"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5
Top GitHub Comments
The following code can solve your problem.
Any chance of making Dagger Hilt views work with Services by default?