Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources
import dev.icerock.gradle.generator.platform.apple.setupExecutableResources
import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks
import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources
import dev.icerock.gradle.generator.platform.apple.setupTestsResources
import dev.icerock.gradle.generator.platform.js.setupJsKLibResources
import dev.icerock.gradle.generator.platform.js.setupJsResourcesWithLinkTask
import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask
Expand Down Expand Up @@ -85,7 +84,6 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
if (target is KotlinNativeTarget) {
setupExecutableResources(target = target)
setupFrameworkResources(target = target)
setupTestsResources(target = target)
}

if (target is KotlinJsIrTarget) {
Expand Down Expand Up @@ -186,6 +184,7 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
sourceSet.resources.srcDir(genTaskProvider.map { it.outputResourcesDir })
sourceSet.resources.srcDir(genTaskProvider.map { it.outputAssetsDir })
}

KotlinPlatformType.androidJvm -> {
// Fix: android sourceSets indexation in IDE
// Usage of api of v2.model in AGP broken for IDE resources indexing
Expand All @@ -200,6 +199,7 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
// see: dev.icerock.gradle.generator.platform.android.SetupAndroidUtilsKt.addGenerationTaskDependency
// androidSourceSet.assets.srcDir(genTaskProvider.map { it.outputAssetsDir })
}

KotlinPlatformType.common, KotlinPlatformType.native,
KotlinPlatformType.wasm -> Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

package dev.icerock.gradle.actions.apple

import dev.icerock.gradle.data.ExtractingBaseLibraryImpl
import dev.icerock.gradle.utils.klibs
import org.gradle.api.Action
import org.gradle.api.Task
import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import org.jetbrains.kotlin.library.KotlinLibraryLayout
import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl
import org.jetbrains.kotlin.library.impl.javaFile
import java.io.File

internal abstract class CopyResourcesFromKLibsAction : Action<Task> {
Expand Down Expand Up @@ -71,7 +71,7 @@ internal abstract class CopyResourcesFromKLibsAction : Action<Task> {
val layout: KotlinLibraryLayout = getKotlinLibraryLayout(klibFile)
return layout.resourcesDir.listFilesOrEmpty
.filter { it.isDirectory && it.extension == "bundle" }
.map { it.javaFile() }
.map { File(it.path) }
Comment thread
Alex009 marked this conversation as resolved.
}

private fun getKotlinLibraryLayout(file: File): KotlinLibraryLayout {
Expand All @@ -83,6 +83,6 @@ internal abstract class CopyResourcesFromKLibsAction : Action<Task> {
// klib path, hash, resources count. to not extract klibs that we already know that not
// contains any resources. BUT maybe extraction will be faster then hashing for this logic.
// so this improvement should be checked in future
return if (klib.isZipped) klib.extractingToTemp else klib
return if (klib.isZipped) ExtractingBaseLibraryImpl(klib) else klib
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.icerock.gradle.actions.js

import dev.icerock.gradle.data.ExtractingBaseLibraryImpl
import dev.icerock.gradle.utils.klibs
import org.gradle.api.Action
import org.gradle.api.logging.Logger
Expand Down Expand Up @@ -129,7 +130,7 @@ internal class CopyResourcesToExecutableAction(
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path)
val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default")
val layout: KotlinLibraryLayout = if (klib.isZipped) {
klib.extractingToTemp
ExtractingBaseLibraryImpl(klib)
} else {
klib
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.gradle.data

import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.file.file
import org.jetbrains.kotlin.konan.file.unzipTo
import org.jetbrains.kotlin.konan.file.withZipFileSystem
import org.jetbrains.kotlin.library.KotlinLibraryLayout
import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl

/**
* The code in this file is pulled from a previous version of Kotlin to replicate
* removed functionality that MR relies on for extracting klibs.
* https://github.com/JetBrains/kotlin/blob/00984f32ac1ebc2e7fb71b440c282be2a8b05f36/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryLayoutImpl.kt
*/

internal open class ExtractingKotlinLibraryLayout(zipped: KotlinLibraryLayoutImpl) : KotlinLibraryLayout {
override val libFile: File get() = error("Extracting layout doesn't extract its own root")
override val libraryName = zipped.libraryName
override val component = zipped.component
}

internal class ExtractingBaseLibraryImpl(zipped: KotlinLibraryLayoutImpl) : ExtractingKotlinLibraryLayout(zipped) {
override val manifestFile: File by lazy { zipped.extract(zipped.manifestFile) }
override val resourcesDir: File by lazy { zipped.extractDir(zipped.resourcesDir) }
}

private fun KotlinLibraryLayoutImpl.extract(file: File): File = extract(this.klib, file)

private fun extract(zipFile: File, file: File) = zipFile.withZipFileSystem { zipFileSystem ->
val temporary = org.jetbrains.kotlin.konan.file.createTempFile(file.name)
zipFileSystem.file(file).copyTo(temporary)
temporary.deleteOnExit()
temporary
}

private fun KotlinLibraryLayoutImpl.extractDir(directory: File): File = extractDir(this.klib, directory)

private fun extractDir(zipFile: File, directory: File): File {
val temporary = org.jetbrains.kotlin.konan.file.createTempDir(directory.name)
temporary.deleteOnExitRecursively()
zipFile.unzipTo(temporary, fromSubdirectory = directory)
return temporary
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
Expand Down Expand Up @@ -222,37 +221,39 @@ internal fun registerCopyXCFrameworkResourcesToAppTask(
}

internal fun setupExecutableResources(target: KotlinNativeTarget) {
val project: Project = target.project
target.binaries.withType<AbstractExecutable>().configureEach { executable ->
val copyTaskName: String =
executable.linkTaskProvider.name.replace("link", "copyResources")
setupExecutableGradleResources(executable)
setupExecutableXcodeResources(executable)
}
}

project.tasks.register<CopyExecutableResourcesToApp>(copyTaskName) {
dependsOn(executable.linkTaskProvider)
internal fun setupExecutableXcodeResources(executable: AbstractExecutable) {
val copyTaskName: String = executable.linkTaskProvider.name.replace("link", "copyResources")
val project: Project = executable.project

klibs.from(executable.linkTaskProvider.map { it.klibs })
project.tasks.register<CopyExecutableResourcesToApp>(copyTaskName) {
dependsOn(executable.linkTaskProvider)

outputDirectory.set(
project.layout.dir(
project.provider {
val buildProductsDir =
project.property("moko.resources.BUILT_PRODUCTS_DIR") as String
val contentsFolderPath =
project.property("moko.resources.CONTENTS_FOLDER_PATH") as String
klibs.from(executable.linkTaskProvider.map { it.klibs })

outputDirectory.set(
project.layout.dir(
project.provider {
val buildProductsDir =
project.property("moko.resources.BUILT_PRODUCTS_DIR") as String
val contentsFolderPath =
project.property("moko.resources.CONTENTS_FOLDER_PATH") as String

File("$buildProductsDir/$contentsFolderPath")
}
)
File("$buildProductsDir/$contentsFolderPath")
}
)
}
)
}
}

internal fun setupTestsResources(target: KotlinNativeTarget) {
target.binaries.withType<TestExecutable>().configureEach { executable ->
executable.linkTaskProvider.configure { link ->
link.doLast(CopyResourcesFromKLibsToExecutableAction())
}
internal fun setupExecutableGradleResources(executable: AbstractExecutable) {
executable.linkTaskProvider.configure { link ->
link.doLast(CopyResourcesFromKLibsToExecutableAction())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.icerock.gradle.tasks

import dev.icerock.gradle.data.ExtractingBaseLibraryImpl
import dev.icerock.gradle.utils.toKonanFile
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
Expand Down Expand Up @@ -40,7 +41,7 @@ abstract class CopyExecutableResourcesToApp : DefaultTask() {
.forEach { inputFile ->
val klibKonan: org.jetbrains.kotlin.konan.file.File = inputFile.toKonanFile()
val klib = KotlinLibraryLayoutImpl(klib = klibKonan, component = "default")
val layout: KotlinLibraryLayout = klib.extractingToTemp
val layout: KotlinLibraryLayout = ExtractingBaseLibraryImpl(klib)

// extracting bundles
layout
Expand Down
44 changes: 0 additions & 44 deletions samples/compose-resources-gallery/macosApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import java.io.File

plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
Expand Down Expand Up @@ -65,43 +61,3 @@ kotlin {
multiplatformResources {
resourcesPackage.set("dev.icerock.moko.resources.sample")
}

// TODO move to moko-resources gradle plugin
// 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)
}
14 changes: 9 additions & 5 deletions samples/kotlin-2-dynamic-sample/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
Expand All @@ -6,7 +8,7 @@ plugins {

android {
namespace = "app.kotlin2sample.android"
compileSdk = 34
compileSdk = 36
defaultConfig {
applicationId = "app.kotlin2sample.android"
minSdk = 26
Expand All @@ -28,11 +30,13 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ kotlin {

android {
namespace = "app.kotlin2sample.extra"
compileSdk = 34
compileSdk = 36
defaultConfig {
minSdk = 26
}
Expand Down
10 changes: 5 additions & 5 deletions samples/kotlin-2-dynamic-sample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
agp = "8.4.0"
kotlin = "2.1.0"
compose = "1.6.7"
compose-material3 = "1.2.1"
androidx-activityCompose = "1.9.0"
agp = "8.11.0"
kotlin = "2.2.0"
compose = "1.8.3"
compose-material3 = "1.3.2"
androidx-activityCompose = "1.10.1"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 07 12:20:25 NOVT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions samples/kotlin-2-dynamic-sample/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
pluginManagement {
repositories {
mavenLocal()
google()
gradlePluginPortal()
mavenCentral()
maven("https://androidx.dev/storage/compose-compiler/repository/")
mavenLocal()
}
}

dependencyResolutionManagement {
repositories {
mavenLocal()
google()
mavenCentral()
maven("https://androidx.dev/storage/compose-compiler/repository/")
mavenLocal()
}

versionCatalogs {
Expand Down
2 changes: 1 addition & 1 deletion samples/kotlin-2-dynamic-sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ kotlin {

android {
namespace = "app.kotlin2sample"
compileSdk = 34
compileSdk = 36
defaultConfig {
minSdk = 26
}
Expand Down
14 changes: 9 additions & 5 deletions samples/kotlin-2-sample/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
Expand All @@ -6,7 +8,7 @@ plugins {

android {
namespace = "app.kotlin2sample.android"
compileSdk = 34
compileSdk = 36
defaultConfig {
applicationId = "app.kotlin2sample.android"
minSdk = 26
Expand All @@ -28,11 +30,13 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}

Expand Down
Loading
Loading