Closed serbelga closed 1 year ago
https://github.com/serbelga/ToDometerKotlinMultiplatform/pull/164 here configuration for your project.
while compose-jb ios integration is experimental api - we will not add this code to moko-resources plugin. but for all who want use Compose for iOS with resources at now - use this workardound in your ios-app build.gradle:
// copy .bundle from all .klib to .kexe
tasks.withType<KotlinNativeLink>()
.configureEach {
val linkTask: KotlinNativeLink = this
val outputDir: File = this.outputFile.get().parentFile
@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date
val action = object : Action<Task> {
override fun execute(t: Task) {
(linkTask.libraries + linkTask.sources)
.filter { library -> library.extension == "klib" }
.filter(File::exists)
.forEach { inputFile ->
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path)
val klib = org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl(
klib = klibKonan,
component = "default"
)
val layout = klib.extractingToTemp
// extracting bundles
layout
.resourcesDir
.absolutePath
.let(::File)
.listFiles { file: File -> file.extension == "bundle" }
// copying bundles to app
?.forEach {
logger.info("${it.absolutePath} copying to $outputDir")
it.copyRecursively(
target = File(outputDir, it.name),
overwrite = true
)
}
}
}
}
doLast(action)
}
// copy .bundle from .kexe to .app
tasks.withType<ExperimentalPackComposeApplicationForXCodeTask>()
.configureEach {
val packTask: ExperimentalPackComposeApplicationForXCodeTask = this
val kclass = ExperimentalPackComposeApplicationForXCodeTask::class
val kotlinBinaryField =
kclass.declaredMemberProperties.single { it.name == "kotlinBinary" }
val destinationDirField =
kclass.declaredMemberProperties.single { it.name == "destinationDir" }
val executablePathField =
kclass.declaredMemberProperties.single { it.name == "executablePath" }
@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date
val action = object : Action<Task> {
override fun execute(t: Task) {
val kotlinBinary: RegularFile =
(kotlinBinaryField.get(packTask) as RegularFileProperty).get()
val destinationDir: Directory =
(destinationDirField.get(packTask) as DirectoryProperty).get()
val executablePath: String =
(executablePathField.get(packTask) as Provider<String>).get()
val outputDir: File = File(destinationDir.asFile, executablePath).parentFile
val bundleSearchDir: File = kotlinBinary.asFile.parentFile
bundleSearchDir
.listFiles { file: File -> file.extension == "bundle" }
?.forEach { file ->
file.copyRecursively(File(outputDir, file.name), true)
}
}
}
doLast(action)
}
later, when api in compose-jb will be stable - we add integration inside moko-resources gradle plugin
Ok, nice! I have an implementation of the stringResource
function for compose ios on this branch https://github.com/icerockdev/moko-resources/compare/master...serbelga:moko-resources:resources_compose_ios for when compose-jb is stable. I can create a WIP PR if you want
compose for ios support released in 0.21.0
Jetbrains Compose version: 1.3.0-beta01
Link to repo: https://github.com/serbelga/ToDometerKotlinMultiplatform