0

I am building an app that will rely heavily on user data and plan on using Room to help manage and store their information. However, while following a tutorial I ran into a few versioning issues that I was having troubles resolving on my own.

Since I am fairly new to both Android development as well as using Room, I have been following this tutorial: Android Room with a View - Kotlin

I first noticed there might be some issues in step 3 when I updated my Gradle files. I was met by the following error on the last two lines of the dependencies block:

Library should be updated to be compatible with Kotlin 1.3

Library errors from Android Studio I was confused by this since the tutorial uses a variable of some kind to determine the library versions. I ran the app at this point and it seemed to work fine so I continued.

When I got to step 9, I also ran into additional errors which now prevent builds from completing:

Type mismatch: inferred type is kotlin.coroutines.experimental.CoroutineContext but kotlin.coroutines.CoroutineContext was expected 
Type mismatch: inferred type is kotlin.coroutines.CoroutineContext but kotlin.coroutines.experimental.CoroutineContext was expected

This is on top of errors that implementations of kotlinx.coroutines.experimental are obsolete, however, I couldn't find references to libraries without experimental using Android Studio's intellisense. Type mismatch errors form Android Studio

What do I need to do in order to resolve these library issues and allow me to continue the tutorial?

Metomorphose
  • 434
  • 3
  • 14

1 Answers1

0

To the best of my knowledge, here is the recommended way to resolve these issues.

To try and solve these issues, I started with the errors in my Gradle scripts to see if that would maybe resolve dependencies in the code. I did find this post, which I'm still not completely convinced is the best solution, but just following the first couple of suggestions in the top answer did clear most of my issues.

To be clear, I changed the following:

  1. Changed the variable in the last line of the dependencies Gradle block to have a hard-coded version number (I did the latest as found in the kotlinx.coroutines repo). If possible, I would like this to be auto-generated again as the tutorial implies
  2. Removed the kotlin block from the bottom of that same Gradle file
  3. Synced my Gradle project
  4. Update Kotlin and Gradle (I was asked by Android Studio, you might not be depending on your versions)
  5. Manually removed problem libraries from code, and Alt+Enter'ed any missing libraries back into existence

If you update Gradle, you may also find it necessary to include the following in your Module: app Gradle file inside the android block:

packagingOptions {
    exclude 'META-INF/*'
}

(* might be overkill for some, but the suggestion from this post didn't completely eliminate all of my errors.)

After all that, I was then able to rebuild the SDK which loaded to my phone with zero errors.

Metomorphose
  • 434
  • 3
  • 14
  • The issue is that tutorial is outdated and it uses experimental coroutines which were moved to stable channel since Kotlin 1.3. What You did was mostly correct. – Pawel Apr 21 '19 at 18:26
  • Is there either a new or updated tutorial? Or is there at least a better way to declare the newer version of `kotlinx-coroutines-android` dynamically (maybe pointing to latest stable)? – Metomorphose Apr 22 '19 at 01:26