kotlinandroid-jetpack-composekotlin-multiplatformcompose-desktop

using android libraries for desktop, compose desktop


In the example for the compose-desktop it got

import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

fun main() = application {
    var isOpen by remember { mutableStateOf(true) }
    var isAskingToClose by remember { mutableStateOf(false) }

it has androidx import.

Would it be possible to run other android libraries like for example Exoplayer and Google Accompanist to the compose desktop that can be used for other desktop environments?


Solution

  • No, it's just a name.

    Compose was originally created by the Android team, and later they collaborated with JetBrains to create a multiplatform version. But the Android team decided not to change the name of the package (for example, by removing the prefix androix), and JetBrains had to use the same package name for compatibility.

    You cannot run any Android-specific libraries - an application created with Compose for Desktop runs as a normal JVM application.

    Depending on how much these libraries depend on Android primitives, it may be easier or harder to port them to Desktop. For example, Coil is literally built around Android framework classes, such as Bitmap, BitmapFactory, ImageDecoder, so porting it would be very difficult. Coil author is doing the port to multiplatform, and 3.0.0 should have it, for now it's in alpha.

    Many of Google Accompanist libraries only makes sense on Android platform. If you need to use some of them on Desktop, you can try copy-pasting the source code to see if it can be run on Desktop.