Compose Multiplatform in Action: Taking It Easy, An Introduction to CMP
Hello everyone!
This series will focus on Compose Multiplatform in Action: Developing Cross-platform Apps from Scratch with Kotlin
I’ll concentrate on developing cross-platform apps for Android
and iOS
In the final days, I’ll also share my findings and insights from my research
目錄
- Compose Multiplatform 實戰:放輕鬆點,初探CMP
- Compose Multiplatform 實戰:初戰,安裝CMP環境吧
- Compose Multiplatform 實戰:續戰,用Wizard創建CMP專案
- Compose Multiplatform 實戰:在Android、iOS模擬器上跑CMP專案
- Compose Multiplatform 實戰:CMP的專案結構理解與編譯配置
- Compose Multiplatform 實戰:CMP中跨平台Android、iOS程式碼的進入點
- Compose Multiplatform 實戰:在CMP的Compose中用Material Design3 Theme
- Compose Multiplatform 實戰:CMP用Compose實作跨平台畫面
- Compose Multiplatform 實戰:使用 expect 和 actual 實現跨平台程式碼
- Compose Multiplatform 實戰:CMP中實作Compose Navigation頁面切換
- Compose Multiplatform 實戰:CMP中透過StateFlow來管理UI狀態
- Compose Multiplatform 實戰:CMP中實作NavigationBar底部欄
- Compose Multiplatform 實戰:CMP中使用koin來依賴注入Dependency Injection
- Compose Multiplatform 實戰:CMP實作跨平台資料庫SqlDelight
- Compose Multiplatform 實戰:CMP中使用ROOM開發跨平台資料庫 & 疑難雜症
Let’s first get a basic understanding of Compose Multiplatform and Kotlin Multiplatform
The term Multiplatform
itself is simply Multi
+ platform
As the name suggests, it means supporting multiple platforms
According to the JetBrains official website,
Compose Multiplatform
allows developers to use Kotlin’s Compose declarative UI
to develop applications
Currently supported platforms include iOS
, Android
, Desktop
, and Web
Some people also refer to it as KMM (Kotlin Mobile Multiplatform)
or CMP (Compose Multiplatform)
, KMP (Kotlin Multiplatform)
In this series, I’ll use CMP
to refer to Compose Multiplatform
to reduce repetition throughout the articles
I hope you can get used to this abbreviation!
Both aim to simplify cross-platform project development
reducing the time spent writing and maintaining the same code for different platforms
You can use Gradle configurations
along with shared source code development to reduce development time
such as developing cross-platform code through commonMain
Compose UI is developed in this layer
Here are the main differences
:
KMP
requires using native platform
code to create the UI layout for target apps
For example:
Android uses xml
to implement layouts
or more recently, Android has evolved to using Compose for UI implementation
iOS
uses SwiftUI for implementation
CMP
extends the KMP concept
It similarly allows writing shared code
and now supports using Compose
to create multi-platform UI
As shown below, I can create multi-platform UI
using just Compose
Of course, this UI is created using Material Design 3
Some might be concerned that it doesn’t match iOS design guidelines
However, my past practical experience has taught me
that when working on projects
most UI designs
are primarily based on iOS screens
Therefore, apart from platform-specific components
careful customization can create screens that look almost identical to iOS
So this aspect depends on each person’s use case
and whether they care about these differences XD
Finally
In these thirty days, I’ll share the following topics
- Understanding CMP basic environment configuration
- Mastering CMP basic creation methods, project configuration, and simulator configuration
- Understanding CMP program entry points
- Using Material Design 3 Theme in CMP
- Concrete methods for implementing UI with Compose
- Using expect and actual to implement cross-platform code
- Understanding how to use Koin for DI injection in CMP
- How to handle Android context requirements in CMP development?
- Implementing DataStore for local persistent storage in CMP
- Implementing local database using SqlDelight in CMP
- Implementing local database using Room in CMP and solving the [KSP2] Annotation value is missing in nested annotations issue
- Importing CocoaPods and using iOS frameworks in CMP projects
- Using cinterop and iOS frameworks in CMP projects
- …and more
Starting tomorrow
I’ll begin writing notes to help everyone better understand Compose Multiplatform
Additionally, CMP is constantly being updated
Based on articles published by Google
It’s likely that more support
will be gradually added to CMP
which is something to look forward to
(Image source: Google Blog)
Since CMP is relatively new
we might encounter various situations
and there isn’t as much information available online
so if you encounter any issues, we can discuss them and learn from each other