Kotlin Multi-Platform Mobile (KMM) is an exciting, growing new technology that allows sharing core code between Android, iOS, and Web. In our workshop, we are going to explore what KMM is, how to setup a project for KMM, walkthrough implementing a core module to a few APIs (network layer, data models, parsers, and business logic), and then consume this core library in an Android (Jetpack Compose) and iOS (SwiftUI) application.
Android
An Introduction To Cross-Platform Mobile Development
Author: Minhazur Rahman, Senior Android Developer @ InRhythm
Overview
As mobile technology continues to evolve, we as developers are faced with the challenge of creating mobile apps that work great on all platforms. Traditionally, this has meant building separate apps for each platform, which is very time consuming and costly. However, with the rise of cross-platform mobile development, developers can now write code once and deploy it across multiple platforms.
We will explore:
- The pros and con of cross-platform mobile development
- How it compares to native development
- Some of the most common tools and frameworks used in cross platform development
What Is Cross-Platform Mobile Development?
Cross-platform mobile development refers to the process of writing code once and deploying it across multiple platforms, such as iOS and Android. This is achieved using frameworks and tools that allow developers to write code in a single codebase and then compile it for multiple platforms.
Cross-platform development offers several advantages over native development, including:
- Cost Savings: With cross-platform development, developers can write code once and deploy it across multiple platforms, reducing the time and cost required to develop separate app for each platform
- Wider Audience: By deploying an app on multiple platforms, developers can reach a wider audience, increasing the app’s potential user base
- Consistent User Experience: Cross-platform development allows developers to ensure that users have a consistent experience across multiple platforms, improving the overall user experience
However, cross-platform development also has some limitations, including:
- Performance Issues: Cross-platform apps may not perform as well as native apps, particularly for complex apps that require heavy processing or graphics
- Limited Access To Native Features: Cross-platform development may not provide access to all of the native features of each platform, limiting the app’s functionality
- Development Limitations: Cross-platform development may limit the development process, as developers may need to compromise on certain features or design elements to ensure compatibility across multiple platforms
Cross-Platform Development vs. Native Development
To better understand the pros and cons of cross-platform development, it’s important to compare it to native development. Native development involves building separate apps for each platform using that platform’s specific language and tools.
Native development offers several advantages, including:
- Access To Native Features: Native development provides access to all of the native features of each platform, allowing developers to create apps with rich functionality and design
- Better Performance: Native apps generally perform better than cross-platform apps, particularly for complex apps that require heavy processing or graphics
- Better User Experience: Native apps can provide a better user experience, as they are designed specifically for each platform, taking into account the unique features and design elements of each platform
Native development has limitations as well:
- Time And Cost: Developing separate apps for each platform can be time-consuming and costly, as developers need to learn multiple programming languages and use platform-specific tools
- Limited Audience: Developing separate apps for each platform may limit the app’s audience, as users may only be able to access the app on one platform
- Inconsistent User Experience: Developing separate apps for each platform may result in inconsistent user experience, as users may have different experiences depending on the platform they are using
Common Tools and Frameworks For Cross-Platform Development
To make cross-platform development easier, there are several tools and frameworks available that allow developers to write code once and deploy it across multiple platforms. Here are some of the most common ones:
- React Native: React Native is a popular framework for building cross-platform apps using JavaScript and React; a popular JavaScript library for building user interfaces. It allows developer to write code once and deploy it on both iOS and Android
- Xamarin: Xamarin is a cross-platform development tool that uses C# to build apps for iOS, Android, and Windows. It allows developers to share code between platforms, reducing development time and cost
- Flutter: Flutter is a popular framework for building cross-platform apps using Dart: a programming language developed by Google. It allows developers to create beautiful and fast apps that work seamlessly across multiple platforms
- Ionic: Ionic is a popular open-source framework for building cross-platform mobile apps using web technologies such as HTML, CSS, and JavaScript. It allows developers to create hybrid apps that work on both iOS and Android
When To Choose Cross-Platform Over Native Development
Choosing between cross-platform and native development depends on several factors, including the app’s complexity, budget, and timeline.
Here are some scenarios where cross-platform development may be the better option:
- Limited Budget: If you have a limited budget, cross-platform development can be a cost-effective solution as it allows you to write code once and deploy it on multiple platforms
- Tight Timeline: If you need to develop an app quickly, cross-platform development can help you save time as you don’t need to write separate code for each platform
- Simple Apps: If your app is simple and doesn’t require access to many native features, cross-platform development can be a good option
- Maintenance: If you need to maintain your app on multiple platforms, cross-platform development can be a more efficient solution as you can make changes to the codebase once and deploy it across all platforms
However, there are also scenarios where native development may be the better option, such as:
- Complex Apps: If your app requires access to many native features or requires heavy processing or graphics, native development may be the better option as it can provide better performance
- Design: If your app requires a unique design that is specific to each platform, native development may be the better option as it allows you to design the app specifically for each platform
- Budget: If you have a larger budget, native development may be a better option as it can provide a better user experience and access to all of the native features of each platform
Conclusion
Cross-platform mobile development is a popular solution for creating apps that work seamlessly across multiple platforms. While it offers several advantages, such as cost savings and a wider audience, it also has limitations, such as performance issues and limited access to native feature.
Choosing between cross-platform and native development depends on several factors, including the app’s complexity, budget, and timeline. By weighing the pros and cons, developers can choose the best solution for their app development needs.
Migrating To Jetpack Compose
Overview
Jetpack Compose has been on the tip of every developer’s tongue since the release of its original 1.0 stable version. Jetpack Compose is Google’s modern toolkit for building native Android UI. It simplifies and accelerates UI development to quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs. Compose UI is defined by creating modular, easily reusable Composable functions.
Declarative UIs have developed into a major innovation trend, lending adoption to be a primary growth curve for web and mobile application development teams.
In William Kingsley’s Lightning Talk session, we will be uncovering the the primary strategies for Migrating To Jetpack Compose:
- Why Migrate To Jetpack Compose?
- Migration Strategies
- Live Demonstrations
- Closing Thoughts
Why Migrate To Jetpack Compose?
Google’s clear directive points towards moving developers towards Declarative UI development tools for future Android mobile development. Compose has been clearly articulated as the “future” of native Android and certainly the target for future platform SDK efforts – likely diverting resources from legacy development paradigms. Therefore, Google will expect Android UI development to migrate to Compose over time.
In order to prep for this full transition, there’s been a particular push for adoption, in order to prep developers for the gradual move:
- Google recommends Jetpack Compose for all new applications from the Android go- to-market platform moving forward
- Updating “View Components” is very error prone and coupled with a rather difficult process for anyone that’s used it previously comparatively to Jetpack Compose
- Jetpack Compose’s views update in response to data – meaning, the development platform has “data binding” capabilities right out of the gate!
- Like other Jetpack components, Compose has excellent backward-compatibility with older Android OS levels – even users with older Android devices can run applications built with Jetpack Compose UI
- New UI developed with Jetpack Compose can be incrementally added to existing applications built with conventional Android UI techniques (i.e. XML-based or code-based UI development). This allows developers to dip a toe in the Jetpack Compose water without a wholesale rewrite of their apps up-front
Jetpack Compose saves developers a substantial amount of time and effort for larger scale application layout files. Compose takes about a third of the average modern development duration, meaning– less code to sift through and more bandwidth to experiment and create!
Migration Strategies
There are two primary avenues to migrate an existing Android application to Jetpack Compose:
- Developing A New Screen Entirely With Compose
- When new screens and features are being created within a developing Android application, Jetpack Compose functions can be accessed interoperably with “View” by using the ComposeView class
- In the case of single-activity applications, using the Navigation component for “View,” a developer can drop their composable functions into the existing framework using ComposeView
These user-friendly functions, pre-built into the Jetpack Compose interface, enable developers to convert each new Compose component without needing to change the underlying navigation or data-source logic.
Example: The below screen split utilizes the aforementioned “new” implementation of Jetpack Compose components, allowing easy transition from an existing Android application infrastructure.
- Taking An Existing Screen And Gradually Transferring Components Into It
- For development teams that are completely “fresh to Jetpack Compose,” this gradual shift is a great way to get familiarized and build a culture around maintenance of a new structural interface
- Using this strategy, a development team can take their time to test out the components in order to ensure UI consistency and functionality
Example: The below screen split utilizes the aforementioned “gradual” implementation of Jetpack Compose components, allowing teams the flexibility to migrate as appropriate to an existing Android application.
Live Demonstrations
William Kingsley has crafted an intuitive demonstration to help guide you through these principles in practicum:
Be sure to follow Kingsley’s entire Lightning Talk to view this impressive demonstration in real time.
Closing Thoughts
Jetpack Compose is a fundamental rethinking of how Android UI is authored. It is a game-changer for Android developers – simplifying layouts and behaviors that once spanned multiple files and formats into an easy to navigate singular UI tree of composable functions with the power of Kotlin in the palm of your hand!
Happy coding!
To learn more about Migrating to Jetpack Compose, along with some live test samples, and to experience William Kingsley’s full Lightning Talk session, watch here.