Зависимости ktor и kotlinx не найдены при сборке фреймворка iOS

Я пытаюсь включить поддержку ktor и kotlinx (serialization и coroutines, если быть точным) в свой проект Kotlin / Native. Все библиотеки работают с версией проекта для Android, но когда я пытаюсь скомпилировать проект Xcode, я получаю ошибки о том, что библиотеки kotlinx.serialization и kotlinx.coroutines не могут быть найдены:

src/commonMain/kotlin/.../.kt:4:16: error: unresolved reference: coroutines
import kotlinx.coroutines.CoroutineDispatcher
               ^
src/commonMain/kotlin/.../.kt:5:16: error: unresolved reference: serialization
import kotlinx.serialization.json.JSON

Вот мой файл Gradle для моего проекта:

plugins {
    id 'kotlin-multiplatform' version '1.3.11'
    id 'kotlinx-serialization' version '1.3.0'
}

ext {
    ktor_version = '1.0.1'
    kotlinx_version = '1.1.0'
}

repositories {
    maven { url "https://kotlin.bintray.com/ktor" }
    maven { url "https://kotlin.bintray.com/kotlinx" }
    google()
    jcenter()
    mavenCentral()
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'

configurations {
    compilerPlugin
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "org.jetbrains.kotlin.mpp_app_android"
        minSdkVersion 15
        targetSdkVersion 27
        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:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'

}

kotlin {
    targets {
        fromPreset(presets.android, 'android')
        // This preset is for iPhone emulator
        // Switch here to presets.iosArm64 (or iosArm32) to build library for iPhone device
        fromPreset(presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'commons-codec:commons-codec:1.10'
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation("io.ktor:ktor-client:$ktor_version")
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlinx_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.9.1"
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                implementation("io.ktor:ktor-client-android:$ktor_version")
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinx_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.9.1"
            }
        }
        androidTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        iosMain {
            dependencies {
                implementation("io.ktor:ktor-client-ios:$ktor_version")
                implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$kotlinx_version"
                implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.9.1"
            }
        }
        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 "link${buildType.toLowerCase().capitalize()}Framework${target.capitalize()}"

    doLast {
        def srcFile = kotlin.targets."$target".compilations.main.getBinary("FRAMEWORK", buildType)
        def targetDir = getProperty("configuration.build.dir")
        copy {
            from srcFile.parent
            into targetDir
            include 'app.framework/**'
            include 'app.framework.dSYM'
        }
    }
}

Любая помощь будет принята с благодарностью, спасибо!


person Spencer    schedule 16.01.2019    source источник


Ответы (2)


Убедитесь, что enableFeaturePreview("GRADLE_METADATA") находится в settings.gradle файле. Как только я добавил эту строку, я смог скомпилировать из Xcode.

person Spencer    schedule 16.01.2019

У меня тоже есть эта проблема. И вдруг это появилось в проекте, над которым я работал несколько месяцев. У меня enableFeaturePreview('GRADLE_METADATA') установлен в settings.gradle. Что могло происходить? Это действительно расстраивает; мой проект внезапно остановился без видимой причины.

person Russell Stewart    schedule 05.03.2020