What is the minimal set to use `Preview` in compose? A have `build.gradle.kts` like i’ll post in thr...
i
What is the minimal set to use
Preview
in compose? A have
build.gradle.kts
like i’ll post in thread shortly, but i receive error when try to build preview
Copy code
plugins {
    id("com.android.library")
    kotlin("android")
}

sourceSets.create("main") {
    java.srcDirs += java.srcDir("src/main/kotlin")
}

android {
    compileSdk = Versions.Android.compileSdk
    defaultConfig {
        minSdk = Versions.Android.minSdk
    }

    buildFeatures {
        compose = true
    }

    compileOptions {
        sourceCompatibility = Versions.javaVersion
        targetCompatibility = Versions.javaVersion
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    composeOptions {
        kotlinCompilerExtensionVersion = Versions.Compose.main
    }
}

dependencies {
    implementation(project(Dependencies.Modules.DesignSystem.shared))
    implementation(project(Dependencies.Modules.DesignSystem.pagecontrol))
    implementation(project(Dependencies.Modules.DesignSystem.badges))
    implementation(Dependencies.Compose.ui)
    implementation(Dependencies.Compose.foundation)
    implementation(Dependencies.Compose.uiTooling)
    implementation(Dependencies.Compose.material)
}
error
Copy code
The following classes could not be instantiated:
- androidx.compose.ui.tooling.preview.ComposeViewAdapter (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.  If this is an unexpected error you can also try to build the project, then manually refresh the layout.  Exception Details java.lang.ClassNotFoundException: androidx.lifecycle.runtime.R$id   at java.lang.ClassLoader.loadClass(ClassLoader.java:589)   at java.lang.ClassLoader.loadClass(ClassLoader.java:522)   at androidx.lifecycle.ViewTreeLifecycleOwner.set   ... (ViewTreeLifecycleOwner.java:49)   at androidx.compose.ui.tooling.preview.ComposeViewAdapter.init(ComposeViewAdapter.kt:607)   at androidx.compose.ui.tooling.preview.ComposeViewAdapter.<init>(ComposeViewAdapter.kt:205)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   at java.lang.reflect.Constructor.newInstance(Constructor.java:490)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)   at android.view.LayoutInflater.inflate(LayoutInflater.java:657)   at android.view.LayoutInflater.inflate(LayoutInflater.java:499) Copy stack to clipboard
Get this error even when try to preview simple text
Changed module type to
com.android.application
and it starts working
Why? I can want to preview my components in library. Innit?
c
There's a bug open for preview in library modules I believe. Overall Preview basically doesn't work anywhere except for android-app modules. library modules don't work. And it doesn't even compile in compose for desktop.