Kotlin Multiplatform: When will the Android Room Database join the club?

Ryan W
4 min readNov 14, 2023

--

This image was created using an AI image creation program.

Kotlin Multiplatform (KMP) is a groundbreaking framework developed by JetBrains, facilitating the development of cross-platform applications using shared codebases (while sharing UIs is optional). This technology allows developers to write common logic once and deploy it on platforms like iOS, Android, Web, and Desktop, significantly reducing development time and resources.

Room Database, a part of Android’s Jetpack suite, is an abstraction layer over SQLite, simplifying database operations in Android apps. Currently, the Jetpack Room does not support KMP; KMP App projects must seek alternative cross-platform database solutions.

As we can see from the Google IssueTracker, the Android Team started working on Jetpack Room KMP support on 5th September 2023. Its integration with KMP represents a significant step in cross-platform development, enabling developers to utilise Room’s robust database management capabilities across multiple platforms.

Existing Popular Database Alternatives for Kotlin Multiplatform Projects

  1. SQLDelight: SQLDelight stands out as a leading choice for data persistence in Kotlin Multiplatform projects. It generates type-safe APIs from SQL statements and has Android, JVM, and iOS drivers, ensuring broad platform compatibility​​​​​​​​. More details on SQLDelight for KMP can be found here​​.
  2. Realm: Realm is another popular alternative known for its real-time database capabilities and synchronisation features. It provides a robust solution for managing data in real-time applications, and its support for multiple platforms makes it a strong contender in the KMP space.

What can we expect? Integration of Android Room Database with Kotlin Multiplatform

From the IssueTracker, the Google Android team is diligently working on a series of subtasks to integrate the Room Database with Kotlin Multiplatform fully. These tasks are pivotal in ensuring that the integration is seamless and efficient and caters to the diverse needs of developers working on multi-platform projects.

  1. Moving Room-Runtime Sources to androidMain (Issue 309994510):
    This task is fundamental in aligning the Room Runtime environment with the Android platform within the KMP framework.
  2. Creating a Common RoomDatabase (Issue 309993778):
    Creating a common RoomDatabase is a critical step towards a unified database interface that can be used across multiple platforms.
  3. Refactoring for SQLite Multiplatform Drivers (Issue 309995153):
    This involves adapting the Room-Runtime logic and CodeGen logic to utilise the new SQLite multiplatform drivers, ensuring compatibility and performance across different platforms.
  4. Integrating nativeTestApp into Room’s Integration Tests (Issue 309996497):
    This task aims to add native testing capabilities, enhancing the robustness of the integration.
  5. Concurrency Logic and Coroutines (Issue 309996304):
    Moving any remaining concurrency-related logic to Coroutines is key for asynchronous operations, making the database more efficient and scalable.
  6. Room.kt Movement to commonMain (Issue 309995360):
    This involves moving the Room.ktto commonMain, a step towards unifying the codebase for cross-platform compatibility.
  7. DatabaseConfiguration in commonMain (Issue 309995729):
    This task is about moving the DatabaseConfiguration to commonMain, which is crucial for configuring the database in a platform-agnostic manner.
  8. ExperimentalRoomApi to commonMain (Issue 309985033):
    Moving ExperimentalRoomApi to commonMain ensures that experimental features are accessible across platforms.
  9. Coroutine-ifying InvalidationTracker (Issue 309990302):
    The goal is to adapt the InvalidationTracker for Coroutines, enhancing its efficiency and responsiveness.
  10. Making Room Kotlin Test App KMP Compatible (Issue 309997459):
    This involves updating the Room Kotlin Test App to be compatible with KMP, ensuring the testing framework is robust and cross-platform friendly. It has a remark noting that the possibility is uncertain, but we hope it turned out positive.

💡 The Room Kotlin Test App can be worth following from the work-in-progress list because it will demonstrate how Room can work on KMP through the code.

Conclusion

The prospect of the Android Room Database supporting Kotlin Multiplatform is pivotal in cross-platform application development.

While alternatives like SQLDelight and Realm are promising, the integration of Room Database with KMP offers a unique advantage, particularly for existing native Android apps. It enables these applications to transition to KMP with minimal code rewriting, facilitating a smoother and more efficient adaptation to multiplatform needs.

This integration is not just about expanding the capabilities of Room Database but also about streamlining the process of developing and maintaining applications across diverse platforms, ultimately leading to more cohesive and robust app ecosystems.

Good luck to the Google Android team on achieving their goal of introducing KMP support to Jetpack Room!

--

--

Ryan W

Android | Kotlin Multiplatform | Jetpack Compose 📱Releasing Android Apps since 2010 - dealing with the ecosystem not just coding