Develop android app with kotlin

How to develop your first Android app with Kotlin

Android is rising in the ranks as one of the most 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 to create 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:

Build an advanced Android app from scratch

This course offers a hands-on, project-based approach to developing Android applications with the most modern technologies.

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.

Читайте также:  Css chrome width 100

Android 1.0 made its initial debut in 2008 in the United States. Since then, 15 releases have been made to the 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 a files and libraries for creating Android apps as well as tools like the virtual device manager and ADB bridge.

To download Android Studio, go 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 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.

Источник

Create your first cross-platform app

Here you will learn how to create and run your first Kotlin Multiplatform application using Android Studio.

Create the project from a template

You can also watch the video version of this tutorial created by Ekaterina Petrova, Kotlin Product Marketing Manager.

  1. In Android Studio, select File | New | New Project.
  2. Select Kotlin Multiplatform App in the list of project templates, and click Next. Mobile Multiplatform project template
  3. Specify a name for your first application, and click Next. Mobile Multiplatform project - general settings
  4. In the iOS framework distribution list, select the Regular framework option. Mobile Multiplatform project - additional settingsWe recommend using the regular framework for your first project, as this option doesn’t require third-party tools and has fewer installation issues. For more complex projects, you might need the CocoaPods dependency manager that helps handle library dependencies. To learn more about CocoaPods and how to set up an environment for them, see CocoaPods overview and setup.
  5. Keep the default names for the application and shared folders. Click Finish.

The project will be set up automatically. It may take some time to download and set up the required components when you do this for the first time.

Examine the project structure

To view the full structure of your mobile multiplatform project, switch the view from Android to Project.

Select the Project view

Each Kotlin Multiplatform project includes three modules:

Basic Multiplatform Mobile project structure

  • shared is a Kotlin module that contains the logic common for both Android and iOS applications – the code you share between platforms. It uses Gradle as the build system that helps you automate your build process. The shared module builds into an Android library and an iOS framework.
  • androidApp is a Kotlin module that builds into an Android application. It uses Gradle as the build system. The androidApp module depends on and uses the shared module as a regular Android library.
  • iosApp is an Xcode project that builds into an iOS application. It depends on and uses the shared module as an iOS framework. The shared module can be used as a regular framework or as a CocoaPods dependency, based on what you’ve chosen in the previous step in iOS framework distribution. In this tutorial, it’s a regular framework dependency.

The shared module consists of three source sets: androidMain , commonMain , and iosMain . Source set is a Gradle concept for a number of files logically grouped together where each group has its own dependencies. In Kotlin Multiplatform, different source sets in a shared module can target different platforms.

Source sets and modules structure

This is an example structure of a Multiplatform Mobile project that you create with the project wizard in IntelliJ IDEA or Android Studio. Real-life projects can have more complex structures.

Run your application

You can run your multiplatform application on Android or iOS.

Run your application on Android

  1. Create an Android virtual device.
  2. In the list of run configurations, select androidApp.
  3. Choose your Android virtual device and click Run. Run multiplatform app on AndroidFirst mobile multiplatform app on Android

Источник

Оцените статью