BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Google Introduces Room 3.0: A Kotlin-First, Async, Multiplatform Persistence Library

Google Introduces Room 3.0: A Kotlin-First, Async, Multiplatform Persistence Library

Listen to this article -  0:00

Room 3.0 is a major update to Android's persistence library that introduces breaking changes in key areas. The new release focuses on modernizing Android persistence layer around Kotlin Multiplatform and expands platform support to include JavaScript and WebAssembly.

The biggest change in Room 3.0 is that it will no longer generate Java code, producing only Kotlin instead. According to the development team, this simplifies both the codebase and the development process, enabling faster iterations.

Along with Java generation, Room 3.0 is also removes support for Java Annotation Processing (AP) and KAPT:

Room 3.0 is solely a KSP (Kotlin Symbol Processing) processor, allowing for better processing of Kotlin codebases without being limited by the Java language.

As a consequence, Room 3.0 requires the use of KSP and the Kotlin compiler, even for Java-only codebases. The recommended approach in such cases is to isolate Room usage within one dedicated module, so the "Kotlin Gradle Plugin and KSP can be applied without affecting the rest of the codebase".

From an architectural perspective, two additional breaking changes stand out: the removal of the Android’s native SQLite database API (SupportSQLite) and the adoption of a coroutine-first model. Instead of relying on the Android-only APIs, Room 3.0 uses the KMP-compatible androidx.sqlite driver APIs, simplifying development by eliminating the need to maintain two SQL backends.

The adoption of Kotlin coroutines enables fully asynchronous operations. As a result, all DAO functions generated by the library, such as to insert, delete, or query the data, are defined as suspend. Alternatively, they can return a reactive type using Kotlin FLow, capable of emitting multiple values sequentially.

To make it easier for developers to migrate to Room 3.0 and away from Android's native SQL API, Room 2.8.0 introduces androidx.room:room-sqlite-wrapper. This artifact provides a compatibility layer that allows you to convert a RoomDatabase into a SupportSQLiteDatabase:

This provides a temporary bridge for developers who need more time to fully migrate their codebase. This artifact continues to exist in Room 3.0 as androidx.room3:room3-sqlite-wrapper to enable the migration to Room 3.0 while still supporting critical SupportSQLite usage.

As mentioned, Room 3.0 also extends its platform support to JavaScript and WasmJS. This introduces several breaking changes, as many Room 3.0 functions are now suspend functions to properly support web storage, which is inherently asynchronous.

The SQLiteDriver APIs have also been updated to support the Web and a new web asynchronous driver is available in androidx.sqlite:sqlite-web. It is a Web Worker based driver that enables persisting the database in the Origin private file system (OPFS).

With the release of Room 3.0, Room 2 enters maintenance mode and will only receive patch releases on top of 2.8.0, limited to bug fixes and dependency updates, until Room 3.0 reaches stability.

About the Author

Rate this Article

Adoption
Style

BT