Lets-Plot Skia Frontend is a Kotlin Multiplatform library that allows you to embed
Lets-Plot charts in a Compose Multiplatform, Android or Java Swing application.
To run a Compose Multiplatform demo in IntelliJ IDEA simply navigate to MinimalAppMain.kt or MedianAppMain.kt and select "Run <app>
" from the context menu.
Due to SKIKO-948, updates for the Android version of the library are temporarily paused.
The last library version with Android support is available with the following dependencies:
implementation("org.jetbrains.skiko:skiko-android:0.8.4")
implementation("org.jetbrains.lets-plot:lets-plot-compose:2.0.0")
implementation("org.jetbrains.lets-plot:lets-plot-kotlin-kernel:4.8.0")
implementation("org.jetbrains.lets-plot:lets-plot-common:4.4.1")
To use lets-plot-compose in an Android project, special configuration is required in build.gradle.kts
to serve the Skia binaries:
Click to see the code
Code```
////////////////////////////////////////////////////////
// Include the following code in your Gradle build script
// to ensure that compatible Skiko binaries are
// downloaded and included in your project.
//
// Without this, you won't be able to run your app
// in the IDE on a device emulator.
// //////////////////////////////////////////////////////
val skikoJniLibsReleaseAssetName = "skiko-jni-libs.zip"
val skikoJniLibsDestDir = file("${project.projectDir}/src/main/jniLibs/")
tasks.register("downloadSkikoJniLibsReleaseAsset") {
val repoUrl = "https://github.com/JetBrains/lets-plot-skia"
val releaseTag = "v$letsPlotSkiaVersion"
doLast {
val downloadUrl = "$repoUrl/releases/download/$releaseTag/$skikoJniLibsReleaseAssetName"
val outputFile = layout.buildDirectory.file("downloads/$skikoJniLibsReleaseAssetName").get().asFile
if (outputFile.exists()) {
println("File already exists: ${outputFile.absolutePath}")
println("Skipping download.")
} else {
outputFile.parentFile?.mkdirs()
println("Downloading $skikoJniLibsReleaseAssetName from $downloadUrl")
URL(downloadUrl).openStream().use { input ->
outputFile.outputStream().use { output ->
input.copyTo(output)
}
}
println("Download completed: ${outputFile.absolutePath}")
}
}
}
tasks.register<Copy>("unzipSkikoJniLibsReleaseAsset") {
dependsOn("downloadSkikoJniLibsReleaseAsset")
from(zipTree(layout.buildDirectory.file("downloads/$skikoJniLibsReleaseAssetName")))
into(skikoJniLibsDestDir)
doFirst {
delete(skikoJniLibsDestDir)
}
}
tasks.register("cleanSkikoJniLibs") {
doLast {
delete(skikoJniLibsDestDir)
}
}
tasks.named("clean") {
dependsOn("cleanSkikoJniLibs")
}
tasks.withType<MergeSourceSetFolders>().configureEach {
dependsOn("unzipSkikoJniLibsReleaseAsset")
}
////////////////////////////////////////////////////////
```
Make sure the Android plugin is installed.
From menu Tools -> Android -> SDK Manager
setup an Android SDK.
The local.properties
file will be automatically generated.
In case the local.properties
file didn't appear in the project root:
- create it manually
- add property
sdk.dir
pointing to the location of the Android SDK on your system.
For example:
sdk.dir=/Users/john/Library/Android/sdk
From menu Tools -> Android -> Device Manager
setup Android device.
For example, Nexus 10 with Android 12 works well.
Build the project:
./gradlew build
In the Run configurations
toolbar:
- Select
compose-android-min
orcompose-android-median
application - Select the
Android
device - Click
Run
This project and the corresponding community are governed by the JetBrains Open Source and Community Code of Conduct. Please make sure you read it.
Code and documentation released under the MIT license. Copyright © 2023-2024, JetBrains s.r.o.