KMbed is a Gradle/KMP plugin for embedding resources in KMP modules.
The runtime provides an API similar to Android's R-class, zlib compression and kotlinx.io integration.
- Windows x64
- Linux x64
- Linux arm64
- macOS x64
- macOS arm64
- iOS x64
- iOS arm64
- Android Native x64
- Android Native arm64
- Android Native arm32
- JVM
- JS
First, add the required maven repository:
repositories {
maven("https://files.karmakrafts.dev/maven")
}
Using KMbed is as simple as applying the KMbed Gradle Plugin and the runtime.
plugins {
id("io.karma.kmbed.kmbed-gradle-plugin") version "<version>"
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.karma.kmbed:kmbed-runtime:<version>")
}
}
}
}
Resource may be accessed from any source set using the Res
global:
import com.example.foo.Res // Generated resource index
fun main(args: Array<String>) {
val data = Res["my_resource.bin"].asByteArray()
// ...
}
The following configuration properties are avaiable through the kmbed project extension:
kmbed {
// Allows changing the namespace (package name) of the generated resources for the current module
resourceNamespace = "com.example.foo"
// Allows force-disabling resource compression in the resource compiler
compression = true
// Allows adjusting the threshold at which resources are compressed (in bytes)
compressionThreshold = 256
// Custom source sets
kmbedSourceSets {
defaultSourceSets(project)
val customSourceSet by creating {
resourceNamespace = "com.example.foo.bar"
compression = false
}
}
}