https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

Adam Brown

06/23/2022, 5:55 PM
so I've got a common compose module shared by desktop and android, and I'm running into an issue where I need some icon resources to load into views. Is there an accepted way to share these resources in a module that is common to both desktop and android? Android wants an R references of course, and desktop wants a resource path.
l

Landry Norris

06/23/2022, 6:03 PM
a

Adam Brown

06/23/2022, 6:09 PM
Oh tricky! Thanks!
l

Landry Norris

06/23/2022, 6:32 PM
I’m sure we’ll get a built-in solution at some point in the future (hopefully when #compose-ios is ready), but the workaround in the issue should work for now.
Note that the workaround uses reflection on Android, so it could run much slower.
a

Adam Brown

06/24/2022, 12:48 AM
huh, so this is a weird one, I added that resource directory to the android definition, and it lost it's mind about which directory is a module or not. A has the new resource directory, B does not.
A)
Copy code
android {
    compileSdk = android_compile_sdk.toInt()
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].res.srcDirs("src/androidMain/res", "src/commonMain/resources")
    defaultConfig {
        minSdk = android_min_sdk.toInt()
        targetSdk = android_target_sdk.toInt()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}
B)
Copy code
android {
    compileSdk = android_compile_sdk.toInt()
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = android_min_sdk.toInt()
        targetSdk = android_target_sdk.toInt()
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}
that one line is the only difference
3 Views