https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jake

03/24/2019, 6:34 PM
Hey all I’m starting to create multiplatform libraries in Kotlin and I’m having trouble with integrating KTOR into the project. I’ve found several examples of multi gradle project projects that do it, but I can’t figure it out in my single gradle project. Obviously my gradle game isn’t strong. Can anyone point me in the right direction?
Build.gradle
Copy code
plugins {
    id 'kotlin-multiplatform' version '1.3.0'
}

repositories {
    mavenCentral()
}
group 'com.jacob.rakidzich'
version '0.1.01'

apply plugin: 'maven-publish'

kotlin {
    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
            compilations.main.extraOpts '-module-name', 'Core'
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
                implementation 'io.mockk:mockk-common:1.8.13.kotlin13'
                implementation 'com.willowtreeapps.assertk:assertk-common:0.12'
            }
        }
        iosMain {
        }
        iosTest {
        }
    }
}

// From here: <http://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html>
// Apache 2 License

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
settings.gradle
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin-multiplatform") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }

    repositories {
        maven { url '<http://dl.bintray.com/kotlin/kotlin-eap>' }

        mavenCentral()

        maven { url '<https://plugins.gradle.org/m2/>' }
    }

}
rootProject.name = 'untitled'

enableFeaturePreview('GRADLE_METADATA')
g

gildor

03/25/2019, 12:59 AM
Do you have some particular problem?
j

Jake

03/25/2019, 1:01 PM
NVM I figured it out. I was pointing to the wrong version of ktor.