ImanX
ImanX

Reputation: 816

why kotlin multiplatform don't execute and export iOS framework?

I started develop kotlin multiplatform and I developed a simple lib for test. I can exported .jar file for android but I can't export .framework file for iOS. I reviewed other project but I didn't find my issue.

my Gradle script for lib is:

apply plugin: 'kotlin-multiplatform'

kotlin {
targets {
    final def iOSTarget = 
    System.getenv('SDK_NAME')?.startsWith("iphoneos") \
                          ? presets.iosArm64 : presets.iosX64

    fromPreset(iOSTarget, 'iOS') {
        compilations.main.outputKinds('FRAMEWORK')
    }

    fromPreset(presets.jvm, 'android')
}

sourceSets {
    core.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib-common'
    }

    android.dependencies {
        api 'org.jetbrains.kotlin:kotlin-stdlib'
    }
}

Upvotes: 0

Views: 2588

Answers (2)

Ilya Matveev
Ilya Matveev

Reputation: 191

What do you mean by "exporting a framework"? Are you going to use it from another Gradle project or from XCode or from something else?

P.S. Sorry for asking in answers: just have no enough reputation to leave a comment. So I think it would be more convenient to discuss you problem in issues at GitHub.

Upvotes: 0

Diego Palomar
Diego Palomar

Reputation: 7061

Have you added the task to build the actual framework? If not, try adding this code at the end of your build.gradle file:

task packForXCode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'

    inputs.property "mode", mode
    dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode)

    from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile }
    into frameworkDir

    doLast {
        new File(frameworkDir, 'gradlew').with {
            text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
            setExecutable(true)
        }
    }
}

tasks.build.dependsOn packForXCode

The iOS framework will be available on the build/xcode-frameworks directory of your library.

You'll have to configure also your Xcode project to use the framework. For further details you can read Setting up Framework Dependency in Xcode.

Upvotes: 2

Related Questions