Reader small image

You're reading from  Mastering Kotlin for Android 14

Product typeBook
Published inApr 2024
Reading LevelIntermediate
PublisherPackt
ISBN-139781837631711
Edition1st Edition
Languages
Right arrow
Author (1)
Harun Wangereka
Harun Wangereka
author image
Harun Wangereka

Harun Wangereka is a Google Developer Expert for Android and an Android engineer with over seven years of experience and currently working at Apollo Agriculture. Harun is passionate about Android development, never tired of learning, building the tech community, and helping other developers upscale their skills. He is a co-organizer at Droidcon Kenya and a former Kotlin Kenya and Android254 co-organizer. Through these communities, he has been able to impact thousands of developers. He is also an Android author at Kodeco where he has written 8 articles, published a book; Saving Data on Android, Second Edition, and is also a video course instructor. He has given numerous sessions on Android and Kotlin across different communities worldwide.
Read more about Harun Wangereka

Right arrow

Creating Your First Android App

Android, a mobile operating system developed by Google, runs on over two billion devices, such as smartphones, tablets, TVs, watches, and cars, and developers are able to write code that is compatible with these different devices.

In this chapter, we’ll create our first Android app. We will also familiarize ourselves with Android Studio, the Integrated Development Environment (IDE) that we’ll use to develop Android apps. We will also learn some tips, shortcuts, and useful Android Studio features and understand the process of creating a project in Android Studio.

In this chapter, we’re going to cover the following main topics:

  • Android Studio overview
  • Creating your Android app
  • Android Studio tips and tricks

Technical requirements

To follow the instructions in this chapter, you will need to have Android Studio Hedgehog or later (https://developer.android.com/studio/download) downloaded.

You can find the code for this chapter at https://github.com/PacktPublishing/Mastering-Kotlin-for-Android/tree/main/chaptertwo.

Android Studio overview

Developed by Google, Android Studio is the official IDE for creating Android applications. Built upon JetBrains’ IntelliJ IDEA, it provides a comprehensive platform for Android app development. It has all the features to enable you to develop Android apps with ease.

Once you download Android Studio from the official site, you need to download SDKs and set everything up for it to be ready for use. Open your newly installed Android Studio. You will see the following welcome screen:

 Figure 2.1 – Android Studio welcome screen

Figure 2.1 – Android Studio welcome screen

On the top right, we have these quick options:

  • New Project: We use this to create new projects in Android Studio.
  • Open: We use this when we want to open existing projects using Android Studio.
  • Get from VCS: VCS stands for version control system. Examples of VCSs are GitHub, GitLab, and Bitbucket. We can always link our accounts and easily import projects that are hosted on VCS...

Creating your Android app

Follow these steps to create your first Android app:

  1. Tap on the New Project button, which will take you to the Templates screen, as shown in the following figure:
Figure 2.4 – New Project | Templates screen

Figure 2.4 – New Project | Templates screen

The IDE presents us with a variety of options to choose from while creating new projects, as seen in Figure 2.4. To start with, on the right-hand side, we need to choose the specific form factor that we are targeting. By default, Phone and Tablet is selected. We have other options, such as Wear OS if we want to target wearables, Android TV if we want to develop apps that run on Smart TVs powered by Android OS, and, lastly, Automotive, for apps that target Android Auto.

We are going to use the default option since we want to target Android and tablet devices.

Next, we have to choose a template from the options provided. There are several templates that we can use to quickly generate some functionality...

Android Studio tips and tricks

In this section, we’re going to learn about some useful tips, shortcuts, and features in Android Studio.

We’ll start by opening the MainActivity.kt file. When you open the file, you’ll be presented with the following layout:

Figure 2.8 – MainActivity file

Figure 2.8 – MainActivity file

We can now see the code inside the MainActivity.kt file, which is Kotlin source code. Above the tab with the filename, we can see a navigation bar, as shown in the following screenshot:

Figure 2.9 – Navigation bar

Figure 2.9 – Navigation bar

The navigation bar enables you to navigate easily and quickly between the different project files.

We can also switch to the project view to see all the resources in our project. The switch is at the very top of all the directories. By default, it is set to Android view and has more options depending on your preference. Switching to project view gives us the following folder structure:

...

Summary

In this chapter, we created our first Android app. We familiarized ourselves with Android Studio, the IDE that we use to develop Android apps. We also learned about some tips, shortcuts, and useful Android Studio features and understood the process of creating a project in Android Studio.

In the next chapter, we will be covering Jetpack Compose layout basics. We’ll start with an introduction to Jetpack Compose, a declarative way of declaring UIs for our apps.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Kotlin for Android 14
Published in: Apr 2024Publisher: PacktISBN-13: 9781837631711
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Harun Wangereka

Harun Wangereka is a Google Developer Expert for Android and an Android engineer with over seven years of experience and currently working at Apollo Agriculture. Harun is passionate about Android development, never tired of learning, building the tech community, and helping other developers upscale their skills. He is a co-organizer at Droidcon Kenya and a former Kotlin Kenya and Android254 co-organizer. Through these communities, he has been able to impact thousands of developers. He is also an Android author at Kodeco where he has written 8 articles, published a book; Saving Data on Android, Second Edition, and is also a video course instructor. He has given numerous sessions on Android and Kotlin across different communities worldwide.
Read more about Harun Wangereka