- How to Set Up Android Studio for Kotlin Development
- Install Kotlin Plugin for Android Studio
- Create a New Android Project
- Apply Kotlin Plugin to the Project
- Add Kotlin Gradle Plugin
- Apply the Kotlin Android Plugin
- Convert Activity Code from Java to Kotlin
- Bonus: Staying Up-to-Date With Kotlin Versions
- Further Reading
- How to find out the latest version of Kotlin in Android Studio
- How to find out the latest version of Kotlin in Android Studio
- Android kotlin version
- How to update Kotlin.Runtime in Android Studio
- Android Studio 3 Kotlin version
How to Set Up Android Studio for Kotlin Development
Join the DZone community and get the full member experience.
If you have been following the latest trends in the AndroidDev world, you are likely to have heard about Kotlin.
Kotlin is a (not so) new programming language developed by JetBrains, the makers of IntelliJ IDE that the Android Studio is based on. Kotlin is statically typed, it runs on the JVM, and it offers a lot of benefits. There are tons of articles that talk about the advantages of Kotlin in comparison to Java, so I won’t be covering that in this post.
In this post, however, we will learn how to set up Android Studio for Kotlin development and will write our “Hello World” app in Kotlin.
Install Kotlin Plugin for Android Studio
The good people at JetBrains have created an IntelliJ/Android Studio Plugin for Kotlin. First, we’re going to go ahead and install the plugin.
To do this, navigate to Preferences > Plugins > Browse Repositories, search for Kotlin, and click Install, as shown in the figure below.
When the install is complete, you will need to restart Android Studio to apply the new plugin.
Just in case you’re using IntelliJ IDEA 15 or above, you’re in luck. Koltin plugin ships with the IDE.
Create a New Android Project
Now that we have the plugin installed, let’s go ahead and create a new Android project the usual way we would. Navigate to File > New > New Project and follow through the project creation wizard. Select the Create Empty Activity option at the end.
For more information on creating an Android project, check out this guide.
Apply Kotlin Plugin to the Project
The next step is to apply the Kotlin plugin to the project. There is an automated tool to do this but sometimes, the tool messes things up, so let’s just walk through the manual process of applying the plugin in our build.gradle files (both at the project level and the app module level).
Add Kotlin Gradle Plugin
To configure the plugin, we first need to add the plugin to the root project’s build.gradle , the same way it’s done for the Gradle plugin (automatically). Add the plugin to the dependencies closure in the project build.gradle file. The project build.gradle file looks like this:
A few notes about the block of code above:
- We created a variable ext.kotlin_version . The reason we have this is we may have other places in the project where we need to reference the Kotlin version, so it makes sense to “externalize” that value. You can check out this post about externalizing your dependencies versions using gradle extra properties for more info.
- We placed this variable in the buildscript closure. This is because the buildscript is the entry point into this file when the project is being built. If we place the variable outside this closure, this variable won’t be available before the project is built, and the build will fail.
Apply the Kotlin Android Plugin
After adding the Kotlin Gradle plugin, the next step is to apply the plugin. To do this, we need to add apply plugin: kotlin-android to the app-module’s build.gradle file:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' // apply kotlin android plugin
Convert Activity Code from Java to Kotlin
We’ve applied the plugin and setup all we need to, but our “Empty Activity” generated code is still in Java.
Luckily for us, the Kotlin plugin can help us convert our code from Java to Kotlin.
Currently, our Java Activity looks like this:
To do this, select the file and navigate to Code > Convert Java File to Kotlin File, or use the shortcut Command + Alt + Shift + K (I believe you can replace Command with Control if you’re on a PC).
After converting our code to Kotlin, our “Empty Activity” looks like this:
Bonus: Staying Up-to-Date With Kotlin Versions
You’ve made it this far — let’s add a bonus tip!
Kotlin is still heavily being worked on, and there are (frequent) fixes and updates. It’s generally a good idea to stay up to date with the new features and changes in the language. The Kotlin Android Studio plugin helps us manage the versions of Kotlin. If you navigate to Tools > Kotlin > Configure Kotlin Plugin Updates as shown in the screenshots below, you will be able to select the update channel — Stable , Early Access Preview — 1.0.x , or Early Access Preview — 1.1 — which is currently the bleeding edge version.
Further Reading
There are a number of great resources scattered around the internet for learning Kotlin. Some of them are:
In future posts, I’ll be writing about some specific features of the language.
Thanks for reading this post. I am always open to questions and comments. If you have any, kindly drop them in the comments section below or send me a tweet.
If you found this post useful, or know someone that may find it useful, please feel free to share. Thank you!
Opinions expressed by DZone contributors are their own.
How to find out the latest version of Kotlin in Android Studio
Solution 1: You can update and install new Kotlin plugin from Android Studio itself. Searched in the following locations: https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.pom https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.jar https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.pom https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.jar Solution 1: I Faced the same problem on Android Studio version 3.2 , and I changed this: in File, to this: and Sync now or restarted Android Studio .
How to find out the latest version of Kotlin in Android Studio
I have opened an Android Studio project which was created some time ago and the IDE says that a gradle plugin for Kotlin supports a Kotlin version 1.2.51 or higher. I would like to set it to the latest version but I have to go to the Kotlin website on which it’s not easy to find out this information.
Is it possible to find out the latest version of kotlin in Android Studio?
If you are on windows do the following:
FILE > SETTINGS > LANGUAGE AND FRAMEWORK > KOTLIN UPDATES
then click on check and then if there was a newer version press install
Preferences -> Languages & Frameworks -> Kotlin
How can I get the current Android SDK version, import android.os.Build import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import …
Android kotlin version
Does anyone face below issue? Can somone help on this. Current gradle version 4.4 in dist
Could not find org.jetbrains.kotlin:kotlin- gradle-plugin :1.2.50-eap-62. Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/ kotlin-gradle-plugin /1.2.50-eap-62/ kotlin-gradle -plugin-1.2.50-eap-62.pom
- https://dl.google.com/dl/android/maven2/org/ jetbrains/kotlin/kotlin-gradle-plugin /1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.jar
- https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.pom
- https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin/1.2.50-eap-62/kotlin-gradle-plugin-1.2.50-eap-62.jar
I Faced the same problem on Android Studio version 3.2 , and I changed this:
in build.gradle(Project:»Your Project Name») File,
and Sync now or restarted Android Studio .
I had the same problem, I am not sure my answer is correct. But you can try it. I changed this:
and restarted Android studio.
I faced the same problem when i update my Android Studio . i solved
If you used classpath ‘io.fabric.tools:gradle:1.25.1’
than you need to change classpath ‘io.fabric.tools:gradle:1.+’
Recently I too had the same problem after updating my android studio to 3.5.
I tried the following to resolve this issue.
- Changed kotlin version to 1.3.21 ( ext.kotlin_version = ‘1.3.21’ ) buildscript
ext.lifecycleVersion = '2.2.0-alpha03' ext.kotlin_version = '1.3.21' repositories < maven < url 'https://maven.fabric.io/public' >google() maven < url "https://maven.google.com" >jcenter() > dependencies
Then all worked fine for me after synched the project.
Android Studio : Could not get unknown property, current community. Stack Overflow help chat. Meta Stack Overflow your communities java android android-studio kotlin gradle. Share. Follow …
How to update Kotlin.Runtime in Android Studio
Windows 10, Android Studio 3.0.1. Just fired it up and got the «there’s a new version available, update?». I updated. Now I get «Outdated Kotlin.Runtime. Version of Kotlin runtime is outdated in several libraries» followed by a long URL.
So I need to update the Kotlin Runtime. How do I do that?
You can update and install new Kotlin plugin from Android Studio itself. See
Open the «root» build.gradle of your project. At the very beginning you should find something like this:
change te second line to looks like:
How you should know exactly to which version to update the Kotlin runtime? Easy, take a look to the Event Log in Android Studio, the Kotlin plugin will complain there:
After version 3 of Android Studio you don’t need the Kotlin plugin, just uncheck it. The Kotlin version will look after itself, via a metadependency variable.
In latest version of android studio it is even easier:
Finally restart Android Studio.
Android Studio 3 Kotlin version, In buildscript (project level gradle) I already changed ext.kotlin_version = ‘1.1.4-2’ to ext.kotlin_version = ‘1.1.4-3’ I tried rebuilding …
Android Studio 3 Kotlin version
On start Android Studio 3 beta 2 i get this message:
«Your version of Kotlin runtime in ‘kotlin-stdlib-1.1.4-2’ library is 1.1.4-2, while plugin version is 1.1.4-release-Studio3.0-3. Runtime library should be updated to avoid compatibility problems.»
In buildscript (project level gradle) I already changed ext.kotlin_version = ‘1.1.4-2’ to ext.kotlin_version = ‘1.1.4-3’
I tried rebuilding and cleaning the project but none works, i still get that message on start.
buildscript < ext.kotlin_version = '1.1.4-3' ext.app_compat_version = '26.0.1' ext.google_play_services = '11.2.0' ext.firebase_ui_version = '2.1.1' ext.retrofit_version = '2.3.0' repositories < google() jcenter() >dependencies < classpath 'com.android.tools.build:gradle:3.0.0-beta3' // update kotlin to 1.1.4-2 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 'com.google.gms:google-services:3.1.0' classpath ('com.google.firebase:firebase-plugins:1.1.0')< exclude group: 'com.google.guava', module: 'guava-jdk5' >> > allprojects < repositories < google() jcenter() >> task clean(type: Delete)
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android < compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig < applicationId "" minSdkVersion 16 targetSdkVersion 26 versionCode 1 versionName "0.0.1 - Alpha" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" >buildTypes < release < minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' >> > dependencies < implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' //SUPPORT implementation "com.android.support:appcompat-v7:$app_compat_version" implementation "com.android.support:design:$app_compat_version" implementation "com.android.support:cardview-v7:$app_compat_version" //GOOGLE PLAY SERVICES compile "com.google.android.gms:play-services-auth:$google_play_services" //FIREBASE implementation "com.google.firebase:firebase-auth:$google_play_services" implementation "com.google.firebase:firebase-database:$google_play_services" //FIREBASE UI compile "com.firebaseui:firebase-ui-auth:$firebase_ui_version" //TRANSITIVE LIBS compile "com.android.support:preference-v7:$app_compat_version" compile "com.android.support:customtabs:$app_compat_version" >apply plugin: 'com.google.gms.google-services'
Ok since i removed test depencencies:
testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
problem is gone, but i don’t know why so don’t ask me.
classpath 'com.android.tools.build:gradle:3.0.0-beta3'
because with this classpath we can use kotlin-version 1.1.4-3
Android Stuido: How to change Kotlin version that is, Android Studio is giving a warning saying: «Kotlin version that is used for building with Gradle (1.3.10) differs from the one bundled into the IDE …