Reputation: 3769
from Kotlin Native 0.5, we can compile the kotlin code into a framework
for integrating into an existing iOS project.
I just wonder how to do it?
What I want
I know there is a calculator
sample in the samples
folder, and it adds an extra step called Compile Kotlin framework
in the Xcode
project to do the magic. But I don't know how to separate that step.
I tried using command line like this: ../../dist/bin/kotlinc ./src/main/kotlin/org/konan/arithmeticparser/Parser.kt -produce framework -o asd.framework
.
But the result has a different structure compare to the gradle build one.
Any help here? Thanks
Upvotes: 1
Views: 1389
Reputation: 4992
Yet another tutorial is here https://kotlinlang.org/docs/tutorials/native/apple-framework.html You may probably use Gradle as the build system, see https://github.com/JetBrains/kotlin-native/blob/master/GRADLE_PLUGIN.md
Upvotes: 0
Reputation: 924
You can follow this tutorial here. Although it uses gradle, but it basically includes a script that automatically rebuilds the kotlin framework for ios. Im not sure this is what you require, but you can write a shell script on the same principles.
task lipo(type: Exec, dependsOn: 'build') {
def frameworks = files(
"$buildDir/konan/bin/iphone/${frameworkName}.framework/$frameworkName",
"$buildDir/konan/bin/iphone_sim/${frameworkName}.framework/$frameworkName"
)
def output = file("$buildDir/konan/bin/iphone_universal/${frameworkName}.framework/$frameworkName")
inputs.files frameworks
outputs.file output
executable = 'lipo'
args = frameworks.files
args += ['-create', '-output', output]
}
task copyFramework(type: Copy, dependsOn: lipo) {
from("$buildDir/konan/bin/iphone") {
include '*/Headers/*'
include '*/Modules/*'
include '*/Info.plist'
}
from "$buildDir/konan/bin/iphone_universal"
into "${rootProject.rootDir}/ios"
}
Upvotes: 1