Setup Kotlin EAP in your Android project

Setup Kotlin EAP in your Android project
EAP stands for Early Access Preview. It’s how JetBrains share version of code that are not yet considerable stable but are on their way to be there.
Maybe you read in the news that Kotlin next version will bring some super amazing features X and Z and you would like to try them out or maybe start preparing your App for those changes. So here we are going to see which are the steps to be on the cutting edge of Kotlin 😎
So these are the steps that we need to do:
- Kotlin Plugin: The plugin enriches the IDE by providing all Kotlin specific functionality like suggesting you to use a lambda, use String interpolation and also to understand Kotlin code. Updating this will bring all EAP new stuff to your IDE.
- Kotlin Dependencies: Here we are going to configure repositories, classpath and Kotlin standard library version so Gradle can resolve this EAP version.
- Migration Tool (Optional): If you have a library that depends on an old Kotlin version then you will need to do a migration process. Android Studio already comes with something to help on this.
There is a TL;TR at the end of the post for reference.
1. Kotlin Plugin
Fortunately, as JetBrains is the one behind Android Studio, the IDE already come with all the tools that you need to switch to an EAP version. So go to:
Android Studio > Tools > Kotlin > Configure Kotlin Plugin Updates

Other option: Preferences > Languages & Frameworks > Kotlin Updates

In this section you will be able to set the “Update channel”. Channels give you access to different version of the Kotlin Plugin like the “Stable”, which it’s name is self-descriptive or the EAP versions that we were looking for.
In this example I’ll choose EAP 1.3 (latest available by the time of writing this post):

Press Install and then restart the IDE to apply this change. After restart, if I go again to this preference screen it will said:
Current Kotlin Plugin version “1.3-M2-release-Studio3.2–1”
And that’s all you need for the Plugin. Let’s continue with the dependencies.
2. Kotlin Dependencies
EAP libraries are not public in the regular repositories like JCenter or Maven as they are not yet released so we first need to add this repository to our Gradle file.
If I open the root build.gradle file I’ll see there is a warning telling me that my project is using a different version than the version of the installed plugin (the one that we just updated):

“Kotlin version that is used for building with Gradle (your current version) differs from the one bundled into the IDE plugin (latest)”
Let’s manually change the Kotlin version in this file to the version that I want to change:
buildscript {
ext.kotlin_version = '1.3-M2'
...
Now if I run gradle you will see this beautiful error:

It said that it could not find that library in JCenter neither in Google repository. As I mentioned before, EAP is not in a public repository so we need to add this repository to our gradle file like this:
buildscript {
ext.kotlin_version = '1.3-M2'
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/kotlin/kotlin-eap"
}
}
...
}allprojects {
repositories {
google()
jcenter()
maven {
url "http://dl.bintray.com/kotlin/kotlin-eap"
}
}
}
Run gradle again and voila! You are ready to start using Kotlin EAP in your project!
After this you will see this Migration Tool, which is the next optional step:

3. Migration Tool (Optional)
This is an optional step. The tool will try to provide suggestions on what you need to change/update to make your code work with the newest Kotlin version.
If you chose to migrate, then the next screen will ask you for the scope of the project to be analyzed and it will provides you with possible changes.

Coroutines Example
As an example, here you have a project using Coroutines and those were located in a experimental package. After running the migration tool, it suggested me to migrate to a stable version of the coroutine library and remove “experimental” from the import namespace:


The tool will tell you what to update but sometimes not for what. In this case I had to change those dependencies to point to the EAP version. I found those versions in the Maven Repository:
implementation("....core:0.25.3-eap13")
implementation("....android:0.25.3-eap13")
And that’s all folks! You can start playing with an EAP version of Kotlin Language.
TL;TR
In IntelliJ IDEA: Go to Tools → Kotlin → Configure Kotlin Plugin Updates, then select “Early Access Preview 1.X” in the Update channel drop-down list, and then click Check for updates.
In Gradle: Add http://dl.bintray.com/kotlin/kotlin-eap
as a repository for the build script and your projects; use 1.X-Mx
as the version number for the compiler plugin and the standard library.
Thanks!
Hope you find this article useful. If that’s the case please don’t forget to give some claps 👏
You can find me on:
- Twitter: https://twitter.com/juanchosaravia
- LinkedIn: https://www.linkedin.com/in/juansaravia