Kotlinx.serialization: cbor package not found in Android Kotlin

Created on 30 May 2020  路  3Comments  路  Source: Kotlin/kotlinx.serialization

Describe the bug
I try to import the package _cbor_ from kotlinx.serialization.cbor* but it says _Unresolved reference: cbor_
Also, the class Cbor isn't available (even if _Json_ class is available and working)

I've tried in many ways, also copy-and-pasting the original code of the CBor class, but an error upon deserialization occurred (something like "started to find a map but found 79, I don't remember right now, but this problem has a lower priority because it's caused by brutally copied code).

My build.gradle (Project: nameOfThatProject) looks like:

buildscript {
ext.kotlin_version = '1.3.72' // '1.3.70' //
ext.serialization_version = '1.3.72'
ext.serialization_plugin_version = '1.3.72'
repositories {
google()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://kotlin.bintray.com/kotlin-eap" }
maven { url "https://kotlin.bintray.com/kotlin-dev" }
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://dl.bintray.com/sandwwraith/libs-preview/"}
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha06"
// for JSON and CBOR
// THIS LINE CAUSES BUILDING PROBLEM classpath 'org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:0.7.0-eap-1' //1.3.72'
classpath "org.jetbrains.kotlin:kotlin-serialization:$serialization_plugin_version" // this not
}
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
id "org.jetbrains.kotlin.plugin.serialization" version "1.3.72"
}
allprojects {
repositories {
google()
jcenter()
}
}
/*
task clean(type: Delete) {
delete rootProject.buildDir
}*/

My build.gradle (Module:app) looks like:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "bc.tryvium"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// used by Auth0
manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "demo"]
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation fileTree(dir: 'libs', include: ['
.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.couchbase.lite:couchbase-lite-android:2.7.0'
// Add the Auth0 Android SDK
implementation 'com.auth0.android:auth0:1.+'
implementation 'com.braintreepayments.api:braintree:2.+'
// to call apis
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
// to let threads communicate with EventBus
implementation 'org.greenrobot:eventbus:3.2.0'
// google maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
}

To Reproduce
Just copy the build.gradle fileS and try to use the Cbor class to decode an object from a string.

Expected behavior
Importing cbor subpackage and founding the Cbor class

Environment

  • Kotlin version: 1.3.72
  • Library version: [e.g. 0.11.0] ???
  • Kotlin platforms: JVM, probably also Native
  • Gradle version: 3.6 [i guess]
  • IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4]
  • Other relevant context [e.g. OS version, JRE version, ... ]
question

Most helpful comment

Add

implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:0.20.0" 

to your dependencies {} section

You may find this guide helpful: https://developer.android.com/studio/build/dependencies

Also, 'org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:0.7.0-eap-1' is indeed obsolete and should not be used.

All 3 comments

Cbor is an artifact of its own. Look here:

Thank you for your link. So, how I add that artifact to the project? I'm sorry if I appear a bit noob in this context.

Add

implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:0.20.0" 

to your dependencies {} section

You may find this guide helpful: https://developer.android.com/studio/build/dependencies

Also, 'org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:0.7.0-eap-1' is indeed obsolete and should not be used.

Was this page helpful?
0 / 5 - 0 ratings