0

我在 Kotlin/Native 示例项目中遇到未解决的依赖项的 gradle 构建错误。

无法解决:org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.8.1-rc13

我的 build.gradle (公共模块)看起来像

apply plugin: 'kotlin-platform-common'
apply plugin: 'kotlinx-serialization'
repositories {
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
jcenter{ url "https://jitpack.io" }
jcenter()
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()

}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"

}

Build.gradle(platform-android 级别)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-platform-android'
android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.phonepe.mykotlinnativesample"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 2
    versionName "2.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

def butterknife_version = '8.8.1'
repositories{
    mavenCentral()
    maven { url "https://kotlin.bintray.com/kotlinx" }
    jcenter{ url "https://jitpack.io" }
    jcenter()
    maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
    maven { url "http://kotlin.bintray.com/kotlin-dev" }
    maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
    maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
    mavenLocal()
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "com.jakewharton:butterknife:$butterknife_version"
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16' // if you use the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.android.support:exifinterface:27.1.1'
expectedBy project(":common")

}

项目级 Build.gradle 看起来像:

apply plugin: 'kotlinx-serialization'
buildscript {
    ext.kotlin_version = '1.3.0-rc-131'
    ext.serialization_version = '0.8.1-rc13'
    ext.serializationRepo = "https://dl.bintray.com/kotlin/kotlinx/"
    ext.serialization_plugin_version="1.3.0-rc-131"
repositories {
    google()
    jcenter()
    maven {
        url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
    }
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
    maven { url "http://kotlin.bintray.com/kotlin-dev" }
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
    mavenLocal()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.9.2"
    classpath "org.jetbrains.kotlin:kotlin-serialization:$serialization_plugin_version"
      }
}

allprojects {
    repositories {
    google()
    jcenter()
    maven {
        url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
    }
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
    maven { url "http://kotlin.bintray.com/kotlin-dev" }
    maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
    mavenLocal()
}
}
repositories {
    google()
    jcenter()
    maven {
    url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
    }
    maven { url "https://kotlin.bintray.com/kotlinx" }
    maven { url "https://dl.bintray.com/kotlin/kotlin-eap" }
    maven { url "http://kotlin.bintray.com/kotlin-dev" }
    maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
    mavenLocal()
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

settings.gradle::

include ':android', ':common', ':myapplication'
enableFeaturePreview('GRADLE_METADATA')

我可以使用哪些正确的版本和存储库来使用序列化?

4

1 回答 1

0

您附加的设置有点奇怪,因为您将 Kotlin/Native 的 'konan' 插件应用到与 'kotlin-platform-common' 插件相同的模块。首先,'konan' 已被弃用,取而代之的是 'kotlin-platform-native'。其次,这些插件应该适用于不同的 gradle 模块,请参阅kotlin multiplatform 参考

关于序列化,它现在有两种风格:一种,Kotlin 1.2 的版本号为 0.6.x(1.2.70 为 0.6.2)并且不支持 Kotlin/Native;仅提供单独的json 解析器。第二种风格,因为 Kotlin 1.3 正处于开发阶段,编号为 0.8.x-rc13(最新的是 Kotlin/Native 0.9.2 的编号为 0.8.1-rc13),它确实在带有坐标的单独工件中包含 K/N 支持“ kotlinx-序列化-运行时-原生”。Kotlin 1.3 预览版的序列化文档揭示了更多信息:https ://github.com/Kotlin/kotlinx.serialization/blob/master/docs/eap13.md 。

还有一个专门的设置示例,其中包含一个可立即使用的带有序列化的多平台项目存根。Branchnative_preview使用前面提到的 Kotlin 1.3-rc、K/N 0.9.2 和序列化 0.8.1。

于 2018-09-30T16:00:45.287 回答