I assume you have Android Studio already installed. If not, head over to the official android website, download it and follow the procedure. As soon as you create a new project, set the name of it and click next. You can skip the next window and click on Finish.
If you have never seen Android Studio before, it will look intimidating. But before we start, let’s actually enable Kotlin support!
Go to File -> Settings and now click on Install Jetbrains plugin…
In the search which will appear on the top, search for Kotlin and click install.
Now, go to Tools in your toolbar, go down to Kotlin, and click on Configure Kotlin in Project
Your settings should be okay, just make sure you’re using the latest version of Kotlin and click on Okay. If you see a yellow bar popping up on top of your Editor, go to the right and click on Sync Now. The final step is to click on Code -> Convert Java to Kotlin File.
Congratulations, everything worked fine. I hope so.
But obviously, we want to be able to see what we are building on an actual device! In case you have an Android device, just plug it into your computer, wait a second and then you’re able to click the green play button on top of Android Studio.
In case you don’t have an Android Phone to your disposal, go to Tools -> Android -> AVD Manager and Create a Virtual Device by clicking on the bottom left.
Okay, we’re good to go now!
The first thing you’ll see some code. (If not, click on the tab called “MainActivity.kt”).
The onCreate function is called as soon as we start the application. The highlighted line of code is responsible for bootstraping your view. It sets our activity_main.xml file as the current view.
By clicking on activity_main.xml right next to MainActivity.kt, you’ll be able to take a look at this window:
this is the design represantation of our file. You see a screen, a palette with availabe widgets and layouts on the top left and a wireframe represantation on the right of the phone. Click on the “Text” on the very bottom left.
What you see now is the actual xml file.
Note: The Design Window is just a visual represantation of the actual xml file and will convert any change you do manually into xml code.
which means, that we can switch between the Design and Text window, while I would still recommend doing the majority of your work inside of the Text window, as it gives you a clearer understanding of what is actually going on.
At this point, you have a very brief understanding of what is going on in our application, although we haven’t written any code yet. On the next part of this series we will tackle writing a very basic any minimalistic app and walk you through how to access widgets in code with Kotlin, handling onClick events, sending little toast messages to your users and more.
I hope you stay tuned for the next part.