Seeing a `has no zero argument constructor` runtim...
# compose
t
Seeing a
has no zero argument constructor
runtime error when using
androidx.lifecycle.viewmodel.compose.viewModel()
🧵
Happens ONLY when the
ViewModel
is in a separate gradle module
The activity:
Copy code
// In Module A
@AndroidEntryPoint
class FooActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            // Breaks when FooViewModel is in a different gradle module
            val fooViewModel = viewModel<FooViewModel>()
            ScreenContent(state = fooViewModel.state)
        }
    }
}
The viewmodel:
Copy code
// In Module B
@HiltViewModel
class FooViewModel @Inject constructor(
    private val getFoo: GetFoo
) : ViewModel() { ... }
Something to do with my setup or could it be a bug?
Hmm just updated dagger/hilt to 2.40.5, seems to have fixed it 🤔
y
Try
hiltViewmodel()
instead of
viewModel()
but first you must add the hilt-compose-navigation lib to your gradle
t
Had the same result with
hiltViewModel()
… the only thing that fixed it was bumping dagger version 😬
195 Views