简体   繁体   English

构建 iOS 框架时找不到 Ktor 和 kotlinx 依赖项

[英]Ktor and kotlinx dependencies not found when building iOS framework

I am trying to include support for ktor and kotlinx ( serialization and coroutines to be exact) to my Kotlin/Native project.我试图在我的 Kotlin/Native 项目中包含对ktorkotlinxkotlinx serializationcoroutines )的支持。 All libraries work on the Android version of the project, but when I try to compile the Xcode project, I receive errors stating that the kotlinx.serialization and kotlinx.coroutines libraries could not be found:所有库都适用于该项目的 Android 版本,但是当我尝试编译 Xcode 项目时,我收到错误消息,指出无法找到kotlinx.serializationkotlinx.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

Here is my gradle file for my project:这是我的项目的 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'
        }
    }
}

Any help would be greatly appreciated, thanks!任何帮助将不胜感激,谢谢!

Make sure enableFeaturePreview("GRADLE_METADATA") is in the settings.gradle file.确保enableFeaturePreview("GRADLE_METADATA")settings.gradle文件中。 Once I added this line, I was able to compile from Xcode.添加此行后,我就可以从 Xcode 进行编译。

I'm having this problem as well.我也有这个问题。 And it suddenly appeared on a project that I've been working on for months.它突然出现在我已经工作了几个月的项目中。 I do have enableFeaturePreview('GRADLE_METADATA') set in settings.gradle .我确实在settings.gradlesettings.gradle enableFeaturePreview('GRADLE_METADATA') What could be going on?会发生什么? This is really frustrating;这真的很令人沮丧; my project is suddenly at a standstill for no apparent reason.我的项目突然无缘无故地停滞不前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS - 使用其他框架依赖项构建静态框架 - iOS - Building a static framework with other framework dependencies 多平台项目的 ios 模块中未解决 ktor 依赖项 - ktor dependencies not resolved in ios module of multiplatform project 在iOS上构建时反应本机viro,未发现框架ViroKit_static_lib错误 - React native viro, framework not found ViroKit_static_lib error when building on ios 构建存档时未找到 Apple 框架 - Apple framework not found when building Archive KMM & KTOR - iOS 项目与框架库在两个目标中导入共享 pod 时崩溃 - KMM & KTOR - iOS project with Framework library crashes when shared pod is imported in both targets Flutter:为 IOS 构建时找不到框架 BoringSSL-GRPC - Flutter: Framework not found BoringSSL-GRPC while building for IOS Android和iOS:如何在构建SDK时处理依赖项 - Android & iOS: How to handle dependencies when building an SDK 在iOS上建立依赖关系时,为什么在“ -reexport_framework”上出现链接器错误? - Why do I get a Linker error on “-reexport_framework” while building dependencies on iOS? 在 Swift IOS 中创建框架文件时如何排除依赖项 - How to exclude dependencies when creating framework file in Swift IOS 在构建设备而不是iOS Simulator时如何仅包括框架? - How to only include a framework when building for device, not iOS Simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM