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

Jake

10/28/2019, 6:57 PM
I’m having some issues starting an MPP project and using KTOR for iOS. Does anyone have any experience with getting this set up properly? My issue is that I can’t seem to import the
HttpClient
and initialize that engine in the iOS project, I keep getting an “Unresolved Reference”. I have no issues creating the engine for Android. Here is my
build.gradle
Copy code
plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.50'
}
repositories {
    google()
    jcenter()
    mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'

ext {
    ktor_version = "1.2.5"
}

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'org.jetbrains.kotlin.mpp_app_android'
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName '1.0'
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
}

kotlin {
    android("android")
    // This is for iPhone emulator
    // Switch here to iosArm64 (or iosArm32) to build library for iPhone device
    iosX64("ios") {
        binaries {
            framework()
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "io.ktor:ktor-client-core:$ktor_version"
            }
        }
        commonTest {
            dependencies {
        		implementation kotlin('test-common')
        		implementation kotlin('test-annotations-common')
            }
        }
        androidMain {
            dependencies {
                implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
                implementation "io.ktor:ktor-client-apache:$ktor_version"
                implementation kotlin('stdlib')
            }
        }
        androidTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        iosMain {
            dependencies {
                implementation "io.ktor:ktor-client-core-native:$ktor_version"
                implementation "io.ktor:ktor-client-ios:$ktor_version" // I saw in Maven that the last recorded version (that I could see) was 1.0.1  - I tried that too
            }
        }
        iosTest {
        }
    }
}

// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
    def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
    def target = project.findProperty('kotlin.target') ?: 'ios'
    dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask

    doLast {
        def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
        def targetDir = getProperty('configuration.build.dir')
        copy {
            from srcFile.parent
            into targetDir
            include 'app.framework/**'
            include 'app.framework.dSYM'
        }
    }
}
e

e5l

10/29/2019, 11:00 AM
Hi @Jake, what version of gradle do you use?
j

Jake

10/30/2019, 12:40 PM
Thanks for asking that. I was on 3.2.1 for some reason. Problem solved.
👍 1
10 Views