Is there no support for Preview in Compose Multipl...
# multiplatform
k
Is there no support for Preview in Compose Multiplatform for Preview lib ? None of Compose Multiplatform Jetbrains sample seems to have it. It would be better to look at the preview instead of build the app.
👀 1
a
Do you support Desktop?
k
No, only iOS and Android
r
did you find an answer?
k
I just added previews composbles in androidMain
1
v
hey @khalid64927 did it work for you? i’m trying to do the same but i don’t find the preview tab 😅. How did you open the preview tab?
k
Preview tab is not available in shared module. You have to view them from Android module like this
@Victor Preview annotation is now available, but only in Fleet IDE in Compose 1.6.0 release
🚀 1
v
Reviving this old thread... I had previews work with Android Studio Koala, in
androidMain
-- until I started using
stringResource
- and now I'm getting Render problem:
Copy code
org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: composeResources/app.client.ui.generated.resources/values/welcome.commonMain.cvr   at _layoutlib_._internal_.kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith   ... (ContinuationImpl.kt:33)
Is there any possible fix for this?
It is currently not in a stage where everyone can use it. But hope that i will be able to provide at least a prototype where you can play with.
Maybe next week
v
wow
it is awesome! 🙂 question.. is it only for desktop right?
t
It will work for code in the common and desktop target.
❤️ 2
And your multiplatform project needs to support the jvm target.
The preview display itself is a compose for desktop app. Which i plant to convert to a intellij plugin
r
Wow, cool man, looking forward to when you release it!
t
Happy new year. I finally released a first prototype of the plugin. Just see following link for details: https://github.com/timo-drick/Mutliplatform-Preview
🙌 1
r
nice job man!
I'm trying to use it but its not working and i don't see the plugin 🤔
t
Oh ok it looks like i forgot to add the ios target
But i did add following targets:
Copy code
kotlin {

    jvm()

    androidTarget()

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "shared"
            isStatic = true
        }
    }
    @OptIn(ExperimentalWasmDsl::class) wasmJs() { browser() }
    ...
Which version of Android Studio do you use?
Which platform targets did you enabled in your gradle file? Can you please show me the content of the kotlin { .. } configuration
r
Android Studio: latest lady bug Platforms: Android & iOS
Copy code
kotlin {
    androidTarget {
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_11)
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
        }
    }

    sourceSets {
        androidMain.dependencies {
            ...
        }
        commonMain.dependencies {
            ...
            implementation("de.drick.compose:hotpreview:0.1.3")
        }
        iosMain.dependencies {
            ...
        }
    }
}
t
You need Android Studio Meerkat to test this plugin.
1
Not sure why you get this error message about the platform target. Unfortunately i never tested with ios targets because i do not have a mac. But in theory it should work.
r
I’ll take a look at the library later and see if I spot any issue But it might be caused by the publishing command, I remember I faced something like that before but not sure
t
Maybe do i need a mac to publish the library? But i do use CI to publish the library.
So it is build on a github server.
r
Yeah, not sure honestly Let me take a look at gradle and the targets and maybe try to build the library locally and see Will let you know if I find the issue
👍 1
Maybe in the evening today or during the weekend
t
I released a new version of the lib: implementation("de.drick.composehotpreview0.1.4") It should work now. I also added JS as target.
r
sorry didn't have the chance to help you out there. I tried using it today, adding the library worked, using the annotation worked but I couldn't see the
preview
tab even after closing the file and reopening it and at some point the file stopped responding then the whole IDE and I had to remove the plugin, and remove the library using
open with TextFile
and restart the IDE to get it back working 😅
did you try it with CMP resources for drawables and fonts?
t
Yes but there are some special cases which will not work correctly. Maybe i will change this how the previews are rendered in the future. Would be really nice if you can point me to a open source project where i can see the problems. There are some problems with the IntelliJ/Android Studio way of handling gradle tasks. I see a problem when you e.g. start a compose for desktop app and than try to recompile. Than the recompile task is stuck until the compose for desktop app is closed.
r
Unfortunately it was not an open source project, but I'll to create one when I'm free and test it there
t
If you want you can have a look here to just see how the plugin works: https://github.com/timo-drick/compose_desktop_dev_challenge
I released a new version at the weekend. It turned out that i forgot to include compose runtime for all platforms. So it now supports also macos and windows. (I verified that it is working on a mac m1) Windows is untested
r
nice job, thank you!