I've created a new project by checking the "include kotlin" box in Android Studio 3 and out of the box I get an error while compiling
"Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jre7..."
I have made sure all plugins are up to date and that the Android SDK is properly installed.
Would anyone know how to solve for this error?
kotlin-stdlib-jre[7/8]
was deprecated a while ago, and has since been removed. The last version available of that specific dependency is 1.2.71. The deprecation notice can be found here. Using an existing version of the stdlib also produces a warning in (at least) Android Studio and IntelliJ.
Use kotlin-stdlib-jdk7
instead. It's the same dependency as kotlin-stdlib-jre7
(except newer), but it was re-named to kotlin-stdlib-jdk
. kotlin-stdlib-jre
is now no longer maintained as a separate dependency.
Both IntelliJ and Android Studio generate new projects using kotlin-stdlib-jre7
; this is a bug. They have likely not updated the generators. Therefore, you have to manually replace the dependencies with working ones until they fix this.
Nevertheless, these are the new valid dependencies as of Kotlin 1.3.0:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Where $kotlinVersion
is either a variable containing the version, or a hard-coded version (i.e. 1.3.0
)
Alternatively, you can use the "plain" stdlib (kotlin-stdlib
) instead of the java-specific versions. But you have to change your dependency either way, so I recommend you go with kotlin-stdlib-jdk7
Note for other build systems
The same actual solution applies to other build systems as well, but the code is different. As there are a lot of build systems, I'm not going to include all of them, but the point is changing the artifact from kotlin-stdlib-jre[num]
to kotlin-stdlib-jdk[num]
(without brackets of course).