Thread
#compose
    clhols

    clhols

    1 year ago
    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)
    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")
    Filip Wiesner

    Filip Wiesner

    1 year ago
    clhols

    clhols

    1 year ago
    Bump!
    Filip Wiesner

    Filip Wiesner

    1 year ago
    Maybe re-post your question If you still have this problem. Or file an issue to Google issue tracker