0

I am getting a gradle build error for unresolved dependencies in a Kotlin/Native sample project.

Failed to resolve: org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.8.1-rc13

my build.gradle (common module) looks like

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 level)

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")

}

Project level Build.gradle looks like:

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')

What are the correct versions and repositories that I can use to be able to use serialization?

Nishita
  • 870
  • 1
  • 9
  • 33

1 Answers1

0

Setup you've attached is kinda strange, because you're applying Kotlin/Native's 'konan' plugin to the same module as 'kotlin-platform-common' plugin. First of all, 'konan' is deprecated and replaced with 'kotlin-platform-native'. Secondly, these plugins should be applied to different gradle modules, see kotlin multiplatform reference.

Regarding serialization, it now comes in two flavours: One, for Kotlin 1.2 has version numbers 0.6.x (0.6.2 for 1.2.70) and does not support Kotlin/Native; only separate json parser is provided instead. Second flavour, for Kotlin 1.3 is under development phase and has number 0.8.x-rc13 (latest one is 0.8.1-rc13 for Kotlin/Native 0.9.2) and it does contain K/N support in a separate artifact with coordinates "kotlinx-serialization-runtime-native". Serialization docs for Kotlin 1.3 preview reveal more information: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/eap13.md .

There is also a dedicated example of setup which contains a ready-to-use stub of multiplatform project with serialization. Branch native_preview uses aforementioned Kotlin 1.3-rc, K/N 0.9.2 and serialization 0.8.1.

sandwwraith
  • 299
  • 1
  • 2
  • 10
  • I need a module with expected classes that I will be "actual" implementing in the platform-modules. I need this module to compile both for ios and android as it will contain common logic for all. Hence, both the konan and kotlin-platform-common plugins – Nishita Oct 03 '18 at 10:03
  • I am still getting the same error for kotlin_version = '1.3.0-rc-57' and serialization_version = '0.8.1-rc13' and kotlin-native:0.9.2 – Nishita Oct 03 '18 at 10:32
  • You have to apply 'kotlin-platform-common' to common module with expected classes and logic, and 'kotlin-platform-native' to ios module with actual classes. apply plugin: 'kotlinx-serialziation' won't work with 'konan', it works only with 'kotlin-platform-native' and 'kotlin-mutliplatform'. 'konan' also uses deprecated model for resolving dependencies; that's probably why you have them unresolved. – sandwwraith Oct 04 '18 at 11:22
  • Also, make sure that you have 'enableFeaturePreview('GRADLE_METADATA')' in your 'settings.gradle', otherwise dependencies won't work. – sandwwraith Oct 04 '18 at 11:23
  • Why are you adding native runtime library to the common module? – sandwwraith Oct 14 '18 at 19:53
  • Doesn't help even if I add runtime-common or remove that dependency all together. Have tried them both. – Nishita Oct 22 '18 at 09:44