I'm using jetpack compose in a project.
I'm using android studio Koala 2024.1.2 Patch 1. I'm using everything almost to the latest versions.
I have a simple composable screen (a bunch of Composable functions that use each other). The only special thing that I'm using into this screen is that I'm using PagingData by creating some composables dynamically, and I'm also using a viewmodel injected with Hilt.
I've struggled to make the preview work because of the usage of ViewModels, but I've workarounded by creating "Content" composables that use the flows in the viewmodel but they don't access the viewmodel itself.
@Composable
fun SlideMovieScreen(viewModel: SlideMovieViewModel = hiltViewModel()) {
val deviceLanguage = getDeviceLocale()
viewModel.setLanguage(deviceLanguage)
val context = LocalContext.current
val vibrator = remember { getVibrator(context) }
SlideMovieScreenContent(viewModel.swipeAction, viewModel.moviesFlow, {
triggerSmallVibration(vibrator); viewModel.onLikeButtonClicked()
}, {
triggerSmallVibration(vibrator); viewModel.onDislikeButtonClicked()
}, {
viewModel.clearSwipeAction()
})
}
@Preview
@Composable
fun SlideMovieScreenPreview() {
val swipeAction =
remember { MutableStateFlow(SlideMovieViewModel.SwipeAction.LIKE).asStateFlow() }
val moviesFlow =
flowOf(PagingData.from(movies))
FilmatchApp {
SlideMovieScreenContent(swipeAction, moviesFlow, {}, {}, {})
}
}
Other than struggling with my preview, which I think it's normal when using ViewModels in jetpack, my main problem is that LiveEdit is not working at all. When I run the app and make a minor change such as changing any color, I just see this error:
Internal error Unexpected error during compilation command java.lang.ClassCastException class.org.objectweb.asm.tree.analysis.BasicValue cannot be cast to class com.android.tools.idea.run.deployment.liveedit.analysis.IntValue
Sorry I can't copy the full error text because when I try to move my mouse cursor to the text, it disappears.
