Android in Kotlin -Part 1.0: Configuring project (Android Studio + Kotlin)
Part 1.0: Configuring project (Android Studio + Kotlin)
In this Part we will configure an Android Studio project to use Kotlin and left everything prepared for the next story to start developing the Android App from the beginning and learning some core concepts.
Creating Android Project
We are going to start from scratch, launch Android Studio and
Hit Start a new Android Studio project
Choose Application name
and Company domain
of your choice > Next
Application name is the name of you App
Company domain is your package name, Your package name is just a unique identifier for your application in the Google Play Store. It can be anything you want as long as it is unique.
Choose Minimum SDK
of your choice > Next
Choose Empty Activity
> Next
Keeping Activity Name
and Layout Name
as default >Finish
This should create your basic project. let’s install the required Plugin for Kotlin.
Android Studio Pref > Plugins > Browse Repositories > search for “Kotlin”
install and restart Android Studio
Our already created MainActivity.java
looks something like this
Now we gonna change MainActivity.java
to kotlin file .
code > convert java file to kotlin file
Here is your MainActivity.kt
Now its time to configure kotlin in your project.
open Find Action(command+shift+A) and start searching “Convert Java to…” > choose All module as an option.
This will update your build.gradle
at app level
apply plugin: 'kotlin-android'compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_ver"
and will add classpath to build.gradle
at project level
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_ver"
Repository
Here you have all the code that we developed
Commit
https://github.com/ziakhalid/android-kotlin-sample/commit/60c6d0812a628c74dcddd37c7047b61d981bda9d
uff… thats it …Hit Run :)
If you find something to improve please let me know, I will try my best to improve this story.
If this article was helpful to you, please do hit the 💚 button below. Thanks!