DEV Community

Cover image for How to develop your first Android app with Kotlin
Hunter Johnson for Educative

Posted on • Originally published at educative.io

How to develop your first Android app with Kotlin

Android is rising in the ranks as one of the more popular operating systems to develop for in this era of mobile development. The OS gives developers a quick time to market (TTM), an open-source platform that can accommodate changing business requirements, and the ability to deploy on multiple platforms.

This makes Android one of the best solutions for creating an application with advanced functionalities.

Android apps are written in either Java or Kotlin. Kotlin is becoming the preferred option by app developers, and Google has even announced that Kotlin is the language of choice. Today, we'll walk you through a tutorial on how to build an Android app using Kotlin.

We will go over:

Android development

History of Android development

Since its inception in 2003, Android has become one of the biggest operating systems in the world for mobile development. Originally a startup that originally set out to improve digital cameras, Android switched their focus to mobile phones in 2004 and was then acquired by Google the following year.

Android 1.0 made its initial debut in 2008 in the United States. Since then, 15 releases have been made for mobile phones that use the operating system, with the last announced release in August 2022 of Android 13.

With that brief history lesson on how Android got started, we’re ready to install our Integrated Development Environment (IDE): Android Studio.

What is Android Studio and SDK?

Created specifically by Google, Android Studio is designed to make Android application development as seamless as possible. According to the Android Developer docs:

“Android Studio is the official IDE for Android app development, based on IntelliJ IDEA.”

With Android Studio, you can test applications either on an emulator or directly on the device. There are several languages are used for Android development. We will discuss these in more detail later.

  • Java/Kotlin: source code
  • Groovy: build scripts
  • XML: layout structure and resources

Android Studio comes with the Android Software Development Kit (SDK), which is a crucial part of Android development. It includes files and libraries for creating Android apps as well as tools like the virtual device manager and ADB bridge.

To download Android Studio, go to the official site and follow the directions to get started under your specific operating system (Windows/Mac/Linux).

If you plan to use an Android Virtual Device instead of a physical device, take a look at the extra requirements needed to run the emulator.

Features of Android Studio

There are several features in Android Studio that make it a worthy IDE for your next project:

  • IntelliJ IDEA: From the Russian company JetBrains, this tool makes app developers more productive in their code writing by assisting with the construction of code. Google based Android Studio on this JetBrains concept. The intelligent code completion can also prevent bugs.

  • Google Play Instant
    Android Studio:
    This tool helps create applications without needing to be downloaded by the user in the Google Play Store. The “Try Now” feature is like a demo version of the application that encourages installs after users have tried the application.

  • Visual Layout Editor:
    Android Studio’s Layout Editor allows you to quickly build layouts for screens by dragging UI components and widgets into a visual design editor. You can create a layout without using XML.

  • Fast Emulator: The Android Emulator enables us to simulate screens in an Android device so we can test our application without a physical device. You can simulate incoming phone calls and text messages, change the location of the device, simulate the physical rotation of the device, and more.

  • New Activity as a Code Template: The latest version of Android Studio gives us different Activity templates that we can use to boilerplate our applications without writing out code by hand. You can also use these templates when adding modules to projects.

Android programming languages

Technologies used in Android development

Now that we have taken a look at the more awesome parts of Android Studio let’s learn about some of the programming languages you will encounter as an Android Developer.

  • Java: Java was originally used as the primary language for Android Development prior to the adoption of Kotlin. It’s a very verbose language, and you may see it in older legacy projects. Java is good to know, but it may be phased out in favor of Kotlin in the future.

  • Kotlin: Kotlin is a cross-platform, statically typed programming language with type inference. Kotlin was created to solve the wordiness of Java. The language fits very well with different Java SDKs, and it is fully interoperable with Java.

  • Android Build System:
    Android Studio uses Gradle to compile your applications. Gradle is a toolkit that automates the build process with your customizations. Gradle will packages your resources into an Android Application Package (APK) that you can test, deploy, and release.

  • XML: Extensible Markup Language, XML, is used to create layout files in Android applications. It is similar to HTML but is stricter. We typically name our XML files to match the name of our activity in our Kotlin or Java files. XML is also used in the manifest.xml file to define components. Think of XML as the skeleton of our user interface.

To understand the difference between Kotlin and Java, compare this Android MainActivity.java file and MainActivity.kt file.

Java:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView mainTextView = findViewById(R.id.mainTextView);
        mainTextView.setText("Hello educative.io");
    }
}
Enter fullscreen mode Exit fullscreen mode

Kotlin:

public class MainActivity : AppCompatActivity {

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val mainTextView = findViewById<TextView>(R.id.mainTextView)
        mainTextView.text = "Hello educative.io"
    }
}
Enter fullscreen mode Exit fullscreen mode

Now that we have an idea of the technologies that are used in creating an Android application, let’s put it all together and create a basic application using Kotlin!

How to set up your first app

To create our first Android application, we want to make sure that you have Android Studio installed. Follow the link in the Android Studio Installation to set up your environment if you haven’t already done so.

Settings in Android Studio

Open up Android Studio. You will be greeted with a couple of options. We are looking to create a new project. When you click on that option, you will be asked about choosing your project.

There are all sorts of screen templates you can choose from. For now, choose “Basic Activity” under the “Phone and Tablet” tab.

Android studio tutorial

You will then be directed to a screen that instructs you to name your application, where to save your application, and whether or not it should be an Instant App-enabled application.

Important! Be sure to choose Kotlin as your language. The default setup at the moment is Java.

The minimum API level is the Android version you would like to develop for. Android provides a handy tooltip to tell you the percentage of devices your chosen API will run on. Your needs may vary, but it's recommended to use API 23: Android 6.0 (Marshmallow).

Click Finish. At this point it will take a minute or so to create the project. Let’s go ahead and create an Android Virtual Device so that we can preview our application in the Android Emulator.

Setup Virtual Device to Test Your Application

An Android Virtual Device (AVD) is a set of characteristics that define the type of device you would like to emulate in the Android Emulator. Android Studio has an AVD Manager that helps us to create and manage our virtual devices.

This means that Android Studio has a place where we can create our virtual phones, tablets, and more so that we can test our applications on them.

  1. Open the AVD Manager by going to Tools > AVD Manager.
  2. Click on ‘+ Create a Virtual Device…’
  3. Select the Hardware that you would like to test on. There are phone, tablet, TV, and Wear OS options. Click Next.
  4. Choose your System Image. This is the Android version you would like to use.
  5. Follow directions if Android Studio tells you you need to download a system image.
  6. Click Next.
  7. Choose orientation of phone to start and then click Finish.

You are now ready to emulate an Android Device in the Android Emulator! Click the Play button in the toolbar to run your application. With the “Basic Activity” template, it comes pre-baked with a basic navigation bar, an action button and a TextView that says “Hello, World!”.

What to learn next

With your setup complete and your Hello World screen running, you are set to either learn Kotlin, or start developing Android applications by using Kotlin. You'll want to learn these things next:

  • How to set up a login screen
  • Building a layout
  • Using widgets
  • Offline solutions

If you have a good handle on Kotlin basics, a good next step is Educative's course Modern Android App Development with Kotlin. In this course, you’ll take a hands-on, project-based approach to learning Android development by building a travel blog application. This course will help you transition to Kotlin.

Happy learning!

Continue reading about Android and Kotlin development on Educative

Start a discussion

What kind of app do you want to create the most? Was this article helpful? Let us know in the comments below!

Top comments (0)