Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack compose lifecycle viewmodel: -> unresolved reference: compose

I copied over the code from this website to play/pause an audio with a single button which changes icons: https://semicolonspace.com/android-compose-music-button/

First I got this error: Jetpack Compose - Unresolved reference: observeAsState but the first anser of the question resolved it.

Now however, on the following line:

androidx.lifecycle.viewmodel.compose.viewModel()

I still get this error: MainActivity.kt: Unresolved reference: compose code-image

There is nothing I can import anymore and I have copied over the code as is on the website.

I refreshed my build.gradle too, such that it takes effect, but didnt help

EDIT:

Here is a github repo in case you would like to inspect this small project yourself, it's just the MainActitiy file, only a few lines of code like on the link above: https://github.com/folsze/unresolved-reference-compose

like image 786
Felix Olszewski Avatar asked May 25 '26 17:05

Felix Olszewski


1 Answers

What really worked for me is that first in the build.gradle file app level I have added the following dependancy

implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"

I have also made sure the androidx.lifecycle:lifecycle-runtime-ktx is version 2.4.1 which wasn't the case

implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'

Here is a repo incase of further inspection https://github.com/waithakaFM/Restaurants

like image 104
Francis Mwangi Avatar answered May 27 '26 20:05

Francis Mwangi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!