We have Compose composables in a submodule and hav...
# compose
c
We have Compose composables in a submodule and have issues with the Preview annotation. Why does @Preview need a "androidx.lifecycle.viewmodel.R$id class?
java.lang.ClassNotFoundException: androidx.lifecycle.viewmodel.R$id
at com.android.tools.idea.rendering.classloading.RenderClassLoader.getNonProjectClassData(RenderClassLoader.java:218)
at com.android.tools.idea.rendering.classloading.RenderClassLoader.loadClassFromNonProjectDependency(RenderClassLoader.java:185)
...
at androidx.lifecycle.ViewTreeViewModelStoreOwner.set(ViewTreeViewModelStoreOwner.java:50)
at androidx.compose.ui.tooling.preview.ComposeViewAdapter.init(ComposeViewAdapter.kt:615)
🧵 4
I have to add the following dependencies in the module to make the preview work:
//Workaround for exceptions during Compose Preview
debugImplementation("androidx.core:core-ktx:${Versions.coreKtx}")
debugImplementation("androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifecycleRuntimeKtx}")
debugImplementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycleViewmodel}")
debugImplementation("androidx.savedstate:savedstate-ktx:1.1.0")
f
Move the looong stacktrace to a thread, please: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1616265877303000
👍 1
c
Fixed it
🙏 1
Bump!
f
Maybe re-post your question If you still have this problem. Or file an issue to Google issue tracker