Albert Gao
Albert Gao

Reputation: 3769

How to compile kotlin native code into an iOS framework?

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

  1. Using command line to build
  2. Build from the kotlin native repo so that I can catch up with the latest update.
  3. Without using Gradle so that I don't need to do a gradle project setup.

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

Answers (2)

Eugene Petrenko
Eugene Petrenko

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

Nishita
Nishita

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

Related Questions