Skip to content

Commit

Permalink
#315: Added workaround using reflection to have compatibility between…
Browse files Browse the repository at this point in the history
… 1.6.10 and 1.6.20-RC
  • Loading branch information
y9san9 committed Mar 17, 2022
1 parent 7dbf60b commit 6829531
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[versions]
kotlinVersion = "1.6.10"
# A separate version for compatibility with future updates
kotlinGradlePluginVersion = "1.6.20-RC"
androidGradleVersion = "7.0.4"

# kotlinx
Expand Down Expand Up @@ -80,6 +82,6 @@ kotlinTest = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotli
kotlinTestAnnotations = { module = "org.jetbrains.kotlin:kotlin-test-annotations-common", version.ref = "kotlinVersion" }

# gradle
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinGradlePluginVersion" }
androidGradlePlugin = { module = "com.android.tools.build:gradle", version.ref = "androidGradleVersion" }
kotlinCompilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlinVersion" }
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
import org.jetbrains.kotlin.gradle.tasks.FrameworkDescriptor
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import org.jetbrains.kotlin.konan.file.zipDirAs
Expand All @@ -41,6 +42,8 @@ import java.util.Properties
import java.util.zip.ZipEntry
import java.util.zip.ZipException
import java.util.zip.ZipFile
import kotlin.reflect.KProperty1
import kotlin.reflect.full.memberProperties

@Suppress("TooManyFunctions")
class AppleMRGenerator(
Expand Down Expand Up @@ -305,16 +308,39 @@ $linkTask produces static framework, Xcode should have Build Phase with copyFram
val fatAction: Action<Task> = object : Action<Task> {
override fun execute(task: Task) {
val fatTask: FatFrameworkTask = task as FatFrameworkTask
fatTask.frameworks.first().outputFile.listFiles()
?.asSequence()
?.filter { it.name.contains(".bundle") }
?.forEach { bundleFile ->
project.copy {
it.from(bundleFile)
it.into(File(fatTask.fatFrameworkDir, bundleFile.name))
}
}

// compatibility of this api was changed
// from 1.6.10 to 1.6.20-RC, so reflection was
// used here.
val fatFrameworkDir: File = FatFrameworkTask::class
.memberProperties
.run {
find { it.name == "fatFrameworkDir" }
?: find { it.name == "destinationDir" }
}?.invoke(fatTask) as File

val frameworkFile = when(val any: Any = fatTask.frameworks.first()) {
is Framework -> any.outputFile
is FrameworkDescriptor -> any.file
else -> error("Unsupported type of $any")
}

executeWithFramework(fatFrameworkDir, frameworkFile)
}

private fun executeWithFramework(
fatFrameworkDir: File,
frameworkFile: File,
) = frameworkFile
.listFiles()
?.asSequence()
?.filter { it.name.contains(".bundle") }
?.forEach { bundleFile ->
project.copy {
it.from(bundleFile)
it.into(File(fatFrameworkDir, bundleFile.name))
}
}
}

project.tasks.withType(FatFrameworkTask::class)
Expand Down

0 comments on commit 6829531

Please sign in to comment.