Tag Archives: app performance

Android Support for Kotlin Multiplatform to Share Business Logic Across Mobile, Web, Server, and Desktop Platforms

Posted by Maru Ahues Bouza – Director, Product Management, and Jeffrey van Gogh – Director, Engineering

Traditionally, developers must either write code individually for each platform they want to target, or make a number of compromises in order to reuse code across platforms. Android has been actively supporting Kotlin since 2017, and today we are excited to announce we are supporting Kotlin Multiplatform on Android, which enables sharing code across mobile, web, server, and desktop platforms. This helps increase productivity for developers, and fits great with Android's Kotlin-first approach, resulting in higher quality Android apps. Our focus is to support sharing business logic (the parts that are most agnostic to the user interfaces) because we've seen Android developers get the most value in not having to maintain duplicate copies of this code.

Kotlin Multiplatform (KMP) has been a long-standing investment for the team behind Google Workspace, allowing for flexibility and speed in delivering valuable cross-platform experiences. The Google Workspace team is enthusiastic about KMP's potential as the direction for its multi-platform architecture investment, confident in its ability to meet performance expectations for various workloads.

The initial step in this journey is the rollout of the Google Docs app for Android, iOS, and Web, which leverages KMP for shared business logic, validating its readiness for production use at Google scale. The Google Workspace team is thrilled to continue exploring the possibilities of KMP across its product suite, aiming to enhance productivity and deliver seamless experiences to users on all platforms.

We see a lot of companies successfully leveraging Kotlin Multiplatform for cross-platform development of their apps, learn how they apply different code-sharing strategies here.

Kotlin Multiplatform, developed by JetBrains, provides a novel approach to sharing code across platforms by compiling Kotlin to platform-native binaries. Kotlin is able to provide the full, modern, memory managed language to native platforms enabling native interoperability and incremental adoption. Kotlin on Android, combined with Kotlin Multiplatform on other platforms, provides a great way to increase productivity and quality, without compromising on performance or interoperability.

Architecture overview for Kotlin Multiplatform (KMP)
Kotlin Multiplatform Architecture

Current Status of Support

Many widely-used libraries offer built-in support for Kotlin Multiplatform, streamlining your cross-platform development experience. These libraries work seamlessly together. For example, Ktor simplifies networking tasks by handling REST service consumption, while kotlinx.serialization converts data to formats like JSON, and Okio manages essential file I/O. Additionally, SKIE facilitates the use of modern types and coroutines on iOS, and CocoaPods integration enables the use of iOS-specific dependencies.

We've worked with JetBrains and the Kotlin developer community to add Kotlin Multiplatform support to a number of Jetpack libraries and in some cases provide the iOS platform targets, while in others, JetBrains and the community provide the multiplatform distributions.

Today, the Annotations, Collections, and DataStore libraries all have support for Kotlin Multiplatform in stable versions. We are also adding support to validate binary compatibility for the iOS platform targets, bringing them on a par with the quality standards for Android. In addition to the libraries above, we've also begun working on Kotlin Multiplatform support for Room, Lifecycle, and ViewModels with alpha versions now available. To better understand which classes and functions are available where, the library reference documentation now indicates "common" and platform support.

Indication of Common, Native and Android support in documentation
Indication of Common, Native and Android support in documentation

Android engineers have collaborated with JetBrains on the Kotlin compiler to improve runtime performance in Kotlin/Native (for iOS & native desktop operating systems), showing 18% runtime performance improvements in compiler benchmarks. In addition the Android team contributed to build time performance improvements for the Kotlin Native Compiler of up to 2x speed ups.

The Android Gradle Plugin now has official support for Kotlin Multiplatform, enabling a concise build definition for setting up Android as a platform target for shared code as shown below:

plugins {
    id("org.jetbrains.kotlin.multiplatform")
    id("com.android.library")
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "11"
            }
        }
    }  
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "Shared"
            isStatic = true
        }
    }    
    sourceSets {
        commonMain.dependencies {
            // put your Multiplatform dependencies here
        }
    }
}
KMP Support in the Android Gradle Plugin DSL

As Android Studio is based on the IntelliJ Platform from JetBrains, it inherits support for Kotlin Multiplatform code editing and many other development features. Other Android development tools like Android Lint and Kotlin Symbol Processing (KSP) are also beginning to add more Kotlin Multiplatform support as well.

Google Chrome now has official support for WasmGC which is used by Kotlin Multiplatform's WebAssembly platform target to enable code sharing with the browser in an efficient and performant way.

Latest details on these projects are available on the updated Android Kotlin Multiplatform page.

Future Areas of Work

We've heard from many Android developers and Google engineering teams that they want expanded support for Kotlin Multiplatform so they can more easily share code with other platforms. Android plans to continue collaborating with JetBrains, Google engineering teams, and the community on a variety of projects, including:

    • Expanding and stabilizing Jetpack libraries with Kotlin Multiplatform support
    • Wasm platform target support in Jetpack libraries
    • Kotlin/Native build performance
    • Kotlin/Native debugging
    • Expanding Kotlin Multiplatform support in Android Studio

Learn More and Try It Out

Sharing code with Kotlin Multiplatform between Android and other platforms enables higher developer productivity and quality so we hope you will give it a try! You can use the Kotlin Multiplatform wizard to create a new KMP project. Learn more in the documentation.

Alternatively, explore one of these sample projects showcasing how to use some of the Jetpack libraries with Kotlin Multiplatform:

If there are additional areas you would like Android to work on let us know and also be a part of our vibrant Android Developer community on LinkedIn, Medium, YouTube, and X.

NordVPN boosted the speed of its login user flow by 60% using Baseline Profiles

Posted by Ben Weiss, Senior Developer Relations Engineer

NordVPN is a virtual private network (VPN) app that protects users while they’re browsing the web by providing them a more secure and private connection. As a network utility, NordVPN’s users deserve a responsive UI, allowing them to set up their protections at a moment’s notice. That's why NordVPN developers recently integrated Baseline Profiles, a profile-guided optimization that helps Android developers improve an app's startup and runtime performance using ahead-of-time compilation.

Improving performance with Baseline profiles

As part of its product roadmap for 2023, the NordVPN team wanted to boost the application’s performance. Before implementing Baseline Profiles, NordVPN’s startup times on Android devices didn’t meet the team’s standards, prompting them to examine new ways to make the app run better.

After exploring ways to improve its runtime performance and streamline the login process for users, NordVPN developers identified an opportunity to make the app faster using Baseline Profiles. Baseline Profiles lets the Android Runtime (ART) know which code paths to optimize through Ahead-of-Time (AOT) compilation before an app launches, boosting speed, stability, and overall responsiveness during startup, when navigating through the app, and while viewing content.

“App speed and stability are essential for a better user experience, so we’re always looking for new ways to improve NordVPN’s performance,” said Himanshu Singh, senior Android engineer at NordVPN. “We wanted to speed up the app’s load time and make launch and navigation faster than ever.”

By applying Baseline Profiles, NordVPN improved its launch speed by an average of 24%. Using tools like Android Vitals, the NordVPN team measured that it had reduced the application’s cold start time from 4.3 seconds to 3.2 seconds, the warm start time from 2.7 seconds to 1.8 seconds, and the hot start time from 1 second to 0.7 seconds.

After implementation, NordVPN developers' also noticed that Baseline Profiles made it faster for users to login to the app, improving the user login flow. The login flow is measured from when a user starts an app to when a user is logged into it. Using the Macrobenchmark library to monitor the improvements, the team observed that the NordVPN app runs its login flow 60% faster than before.

A black quote card featuring a headshot if Ernestas on the right with text in white that reads “The introduction of Baseline Profiles helped us achieve outstanding results, elevating our application’s speed with minimal effort.” — Ernestas Balčiūnas, engineering lead at NordVPN

Integrating and testing Baseline Profiles is easy

The ease of implementing Baseline Profiles impressed NordVPN developers. The available resources, in-depth documentation, and codelabs from Android allowed them to enhance the app’s UX without having to write an extensive amount of code themselves.

Using the Macrobenchmark library, NordVPN developers quickly generated Baseline Profiles for the application. To do this, they used a Gradle managed device, which enabled them to create new profiles without a physical device. Using a Gradle Managed Device also allowed NordVPN developers to create fresh profiles for each app release build on their Continuous Integration platform. Looking forward, NordVPN developers plan to migrate Baseline Profile generation to the official Gradle plugin, which will further automate profile generation.

NordVPN developers combined development workflows to create an integration pipeline, allowing them to test the app under various conditions. Then, the Macrobenchmark library ran Baseline generation tests, pushing the latest Baseline Profiles into the code base.

A black Quote card featuring droid on the right side and a green half oval overlay on the left with white text that reads, 'Applying Baseline Profiles in the NordVPN application led to a 29% improvement to overall in-app speed.'

A quick boost to app quality

After integrating Baseline Profiles into NordVPN’s code, its developers saw immediate speed improvements. The engineering team assessed the app’s overall speed after finishing the project and found that, beyond improving the app’s launch times, applying Baseline Profiles led to a 29% improvement to overall in-app speed.

"We’re constantly working to improve app quality, and Baseline Profiles integration has proven to be one of the most successful steps we’ve taken,” said Šarūnas Rimša, product owner at NordVPN. “We’re helping users access the services they’re entitled to faster. What's not to like?"

Get started

Learn how you can improve your app’s performance using Baseline Profiles.

Working Towards Android App Excellence

Posted by Jacob Lehrbaum Director of Developer Relations, Android

illustration of freckled hand over mobile phone with graphs

Great app experiences are great for business. In fact, nearly three-quarters of Android app users who leave a 5 star review on Google Play mention the quality of their experience with the app1; its speed, design, and usability. At Google, we want to help all developers achieve app excellence, and in turn help you drive user acquisition, retention, and monetization.

So what is “app excellence”? This may sound aspirational, but it is within reach for many apps. It starts with a laser focus on the user, and more specifically, with intuitive user experiences that get people to the main functionality of your app as quickly as possible — but that is just the beginning. Excellent apps are consistent across all of their screens and experiences. They perform well, no matter the device used. App excellence is achievable when all of the stakeholders who influence your app are invested in the experience of using your app.

One of the blockers that gets in the way of app excellence is shared or unclear accountability. Some of the primary measures of app quality, such as crashes and load times, are often seen as the responsibility of one group in the company, such as the engineering team. However, when we talk to best-in-class organizations2 about how they achieve app quality, it is clear that taking a cross-functional approach is key, with engineering, design, product, and business teams working toward a common goal.

So what are some internal best practices behind app excellence?

Make app quality a cross-organizational focus — not just an engineering concern

It’s a way easier conversation for me at the business end because I can say “these competitors’ apps are faster than ours; we need to reduce our load time down from 5 seconds to 4 seconds”.
Software engineer, x-platform app

App excellence helps drive business performance. New features are great, but if they slow down app start-up times or take up too much device space, people will eventually use your app less often or even delete it. Engineers who have built a company-wide focus on quality have often done so by quantifying the impact of quality issues on business performance, through:

  • Case studies showing the impact of responsiveness, APK size, start-up time, and memory usage on business KPIs. Here you can find practical case studies showcasing how developers such as Headspace and Duolingo achieved app excellence.
  • Benchmarking against competitor apps. Check out peer benchmarks and other metrics on the Google Play Console.

Organize teams around features and/or app user journey stages

Companies that organize teams around features — or stages in the user journey — are more likely to deliver consistent experiences across each operating system they support, bring new apps or features to market faster, and deliver a better app experience for all their customers. These teams are often cross-functional groups that span engineering, marketing, ux, and product — and are responsible for the success of a feature or user journey stage3 across all devices and platforms. In addition to better experiences and feature parity, this structure enables alignment of goals across functional areas while reducing silos, and it also helps teams hyper-focus on addressing specific objectives.

Feature organized team graph

Squads focused on business objectives heighten focus on the user.

Use the same devices your customers use

If a majority of your users are on a specific type of device, you can build empathy for their experience if you use the same phone, tablet or smart watch as your primary device. This is especially relevant for senior leadership in your organization who make decisions that impact the day-to-day experience of millions of users. For example, Duolingo has built this into their company DNA. Every Duolingo employee — including their CEO — either uses exclusively or has access to an entry level Android device to reflect a significant portion of their user base.

A user-centric approach to quality and app excellence is essential to business growth. If you are interested in learning how to achieve app excellence, read our case studies with practical tips, and sign up to attend our App Excellence Summit by visiting the Android app excellence webpage.

In subsequent blog posts, we will dig deep into two drivers of excellent app experiences: app performance and how it is linked to user behavior, and creating seamless user experiences across devices. Sign up to the Android developer newsletter here to be notified of the next installment, and get news and insights from the Android team.

Notes


  1. Internal Google Play data, 2021. 

  2. Google App Quality Research, 2021 

  3. The series of steps each user takes as they interact with your app is referred to as the “user journey.” Examples of user journey stages include installs, onboarding, engagement, and retention