Hey Androiders, we are here again quite after a long time to talk about our first “Hello World” Android application with Kotlin. Here we are using Android Studio 3.0.1 to develop out Android Kotlin App. So, before we start I want you to get basic information about kotlin.
Earlier we were using Java to develop Native Android Application in Android Studio. Then Google Announce in Google I/O 2017 that they are going to support Kotlin as “First Class” official language for Android based application development in Android Studio. Kotlin in statically typed programming language which runs on JVM. Designed & developed by JetBrains. We can convert existing java code to kotlin as well and vice versa with no limits. You will get to know more about Kotlin language & how it works later in upcoming tutorials from my side because here after we will be using kotlin language in out upcoming all android related articles.you can start learning from the scratch by Starting Android Development with Android Studio
So, let’s start creating new android project in android studio. Open android studio & click on Start a new android studio Project.
We will give a name as Hello World as It’s our first project. In domain name we will give our company name for me here it is The Android Mania with domain which will reflect in out project main package name trailing by application name. & Check Include Android Kotlin support checkbox as we will be using kotlin language for development. Now it can look as below.
After clicking next to select target Android devices for our application as below.
If you see here I have select Phone and Tablet as supported device which should have minimum android API 21 installed. Which is android 5.0 Lollipop. You can select target APIs as your project needs. For example, if your project is based on basic requirements like some sensors or hardware layer library which is being supported by any low-end device then you can select lower version of SDKs to support maximum android devices available. The lower SDK you select the more devices you can support as simple as that.
Except Phone and Tablet, you can also select Wear, TV, Android Auto or Android Things to develop. You might get to know those types of applications in our upcoming sessions too.
By Clicking next you will see screen to add First Activity and if you don’t want any activity then click on Add No Activity.
You can select activity as per your requirement.
After selecting Blank Screen. Click next. It will take you to below screen.
Here I have given MainActivity name as my Activity Class’s Name which will be Kotlin file for Activity. We will mark checked Generate Layout File checkbox to generate the xml designing file for our activity. We will give layout file name as activity_main & check Backwards compatibility to support older devices.
Now Click Finish to Create project and let android studio create & build a gradle based android project for you. Once it finishes the create & build project it will dismiss the process dialog & display Android Project structure on left side & opened files on Right pane. Here I will show you how the Left pane looks like. I have expanded all the Android Project files which is being used in Android App Development.
You can open MainActivity.kt file which will look like this.
Here we have just put activity_main layout as setContentView() inside onCreate(). So, when our MainActivity will start it will call onCreate() which will set this layout file as the current view.
Here is the activity_main.xml file look like.
This is having just one RelativeLayout as parent layout which is containing a simple TextView which Text is “Hello World” and it is in centre of its parentview as you can see layout_centerInParent property as true.
Let’s have a look at build.gradle file here which is use to build a project using required libraries, sdk & configurations with gradle support.
Here you can see the kotlin dependency “org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version” which is by default get added when we checked the Support for Kotlin while creating a project.
Here below is the AndroidManifest.xml which known as Heart of Android Application. Because it is most important file of project. Which contains all registrations of All Activities, Broadcast Receivers, Services, Intent filters, Permissions etc…
Now we are all done to run our first Hello World Android Application. To run this, we can connect either our Android Mobile with USB cable/WiFi Network or we can make new Android Emulator to run the Application.
That’s it. The Android Studio will start AVD and install Hello World App and it will start app automatically. Next time you can select same AVD to run same app again & again after every modification in code.
Now we are all set to learn more about Developing Beautiful android Apps. Stay tuned! See you soon.
Apple is known to manufacture reliable devices, and iPhones are no exception. It is no…
Introduction to Jio Rockers As teens, we watched movies and TV shows all the time.…
Save Reels, Photo, Video from Instagram using InstantSaver App Instagram just launched new feature Reels specially…
When we talk about calendars, then it is one of the most important things from…
One thing you will definitely find in everyone’s smartphone device users is the selfie camera.…