Android Studio shows Kotlin Dependency Warning after Second Build

Summary

  1. You already fixed it updating your dependencies but I'll answer here to link a related question.

  2. You configured correctly your project dependencies and updated the Kotlin plugin to 1.2.

  3. This is normally enough like here but stdlib-jre dependencies were changed to jdk in Kotlin 1.2.

  4. But your project was depending on Realm version 4.3.1, and they fixed this in version 4.3.2.

  5. You can find the dependency causing the issue via commands or the new build tab in AS 3.1.


1. Add explicit dependencies and update dependencies

Extended versions of the Kotlin standard library are explained in documentation and this answer.

If you're targeting JDK 7 or JDK 8, you can use extended versions of the Kotlin standard library which contain additional extension functions for APIs added in new JDK versions.

Instead of kotlin-stdlib, use one of the following dependencies:

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

In Kotlin 1.1.x, use kotlin-stdlib-jre7 and kotlin-stdlib-jre8 instead.

Update other dependencies, if the automatic resolution doesn't work properly (see point 5).


2. Configure Gradle and Kotlin plugin updates

Revise your Gradle configuration. In order to to build an Android project written in Kotlin:

  • Set up the kotlin-android gradle plugin and apply it to your project.
  • Add kotlin-stdlib dependencies.

Those actions may also be performed automatically in IntelliJ IDEA / AS by invoking the action:

Tools | Kotlin | Configure Kotlin in Project

enter image description here

Check for Kotlin plugin updates:

Tools | Kotlin | Configure Kotlin plugin updates

enter image description here


3. kotlin-stdlib-jre7 renamed to kotlin-stdlib-jdk7 during the 1.2.x release

Sirrah commented on 27 Dec 2017 here:

The Kotlin stdlib was renamed during the 1.2.x release. See here.

The old name kotlin-stdlib-jre7 was changed to kotlin-stdlib-jdk7.

This library is referenced in realm-library and kotlin-extensions.


4. Realm updated to Kotlin 1.2 in 4.3.2 version

Update Gradle Wrapper to 4.4.1 and Update to Kotlin 1.2 (#5642)

  • Update Gradle Wrapper and Update to Kotlin 1.2

  • kotlin-stdlib-jre7 -> kotlin-stdlib-jdk7

enter image description here


5. Find conflictive dependencies via command, or build tab since AS 3.1

./gradlew -q dependencies app:dependencies --configuration variantDebugCompileClasspath

enter image description here

Since Android Studio 3.1 Beta 1, you can use the new build tab to find the conflictive dependency:

enter image description here

enter image description here

enter image description here

In this case, you removed the warning and fixed the issue updating Realm version to 4.3.2:

enter image description here

enter image description here

It's also possible to check it in Travis-ci builds considering the order dependencies are downloaded:

enter image description here


what you can also do is to simply remove(or move) extra version folders. for example, remove one of the two folders below, then rebuild and that should get rid of the kotlin runtime warning.

~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.10

~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.10