Does the world need another cross-platform framework? Tough, here's JetBrains with Compose Multiplatform

'A different way of thinking about applications' says project lead


An open-source Kotlin framework for cross-platform applications, based on Jetpack Compose for Android, is now in preview.

Google's Jetpack Compose is an official framework for building a user interface in an Android application, and reached version 1.0 last week, at the same time as the first stable release of Android Studio, 2020.3.1 or "Arctic Fox".

Despite only just hitting 1.0, Google said: "There are already over 2,000 apps in the Play Store using Compose – in fact, the Play Store app itself uses Compose."

Compose is a declarative framework which moves away from the traditional Android approach of a hierarchy or tree of layouts and controls. A Compose user interface is defined by writing functions annotated with the @Composable annotation, which describe the screen state: the functions generate the user interface. "As app state changes, your UI automatically updates, making it a lot simpler to build UI quickly," said Google's Android team.

Jetpack Compose for Android has just reached version 1.0

Jetpack Compose for Android has just reached version 1.0

Compose is a Kotlin framework, and both Kotlin and Android Studio (the official Android IDE) came from developer tools company JetBrains. Although Jetpack Compose is Android only (unlike Google's Flutter framework), JetBrains believed Compose could also be cross-platform. Compose Multiplatform is a port of the framework for macOS, Linux, Windows, and Web. Version 1.0 Alpha has just been released. Although it is an early version, JetBrains told us that it "provides stable APIs that developers should be already safe to use."

We asked Nikolay Igotti, the Lead for Compose at JetBrains, why the company is investing in Compose for Desktop when it already has a cross-platform Java framework for desktop applications, used in its IntelliJ IDEA IDE and its many variants. "That is pretty much Swing with some modifications," Igotti said. "Swing is the default JDK UI framework, Swing and AWT (Abstract Windows Toolkit). Compose is a completely different framework, although we provide interoperability… Swing is a pretty old framework, released in the late '90s, since then people have changed the way they think about UI."

A Compose for Desktop project in the JetBrains IDE

A Compose for Desktop project in the JetBrains IDE

Compose has one thing in common with Swing: it draws its own controls, unlike some cross platform frameworks – Java's SWT (Standard Widget Toolkit), or Microsoft's Xamarin, for example – which use native controls. Compose uses the Skia open-source graphics library, also used by Google Chrome, Flutter, and many other frameworks. Does that mean a Compose application will not have a native look and feel? "It's up to the developer, how they theme their application," said Igotti. "It's a situation similar to other frameworks like Flutter in that regard."

Does a Compose for Desktop application depend on the JVM (Java Virtual Machine)? "We realise that distribution of a JVM application can be somewhat tricky," Igotti told us. "We have our own Gradle plugin and this is using jpackage and Jlink for making native applications out of JVM applications. You get .dmg for Mac, MSI for Windows, .deb package for Linux, you don't think about the JVM." That said, it is a JVM application under the covers, even though there is a Kotlin/Native compiler which avoids this. "It will be used in the future or for desktop development," said Igotti.

Compose for Desktop: a start

Compose for Desktop: a start

What about web applications? "We use the Kotlin/JS compiler," Igotti said. The web version of Compose is not as far advanced as the desktop version, and the docs warn that "the API is not finalized and breaking changes can be expected." Further, while the web version does use the Compose model, the API is different and uses HTML and CSS so less code can be shared with Compose for Desktop.

"Compose is a different way of thinking about applications," said Igotti. "State is a source of truth for UI, and UI is stateless, it is always computed from the state. In this regard, Compose [for web] shares the same set of primitives, the state management is shared. If you talk about the exact set of widgets, how they are arranged, it's not shared," said Igotti.

What is the main driver behind extending Compose from Android to these other platforms? "The target audience for Compose is three groups of people. First is Android developers using Kotlin and Compose who want to deliver to other platforms. Another is Kotlin developers who want to write new applications that 'write once, run anywhere.' Third is people who are not familiar with Kotlin or Compose but want to create an attractive UI, we want to provide them with the tooling to do that easily."

Igotti did not want to commit to dates, but said that he hopes a beta release will be delivered "mid-autumn" and "we hope for 1.0 sometime this year." The project is open source and "it's a general attitude in the 21st century that people do not charge for frameworks," said Igotti, with the JetBrains business model based on the tooling. "We want to create a missing piece of software," he said.

Note that Compose does not have a visual designer. "Most vendors want to move away from graphical UI builders," said Igotti, in favour of a declarative UI and ways to see this in preview. "We provide a preview mechanism so that if you put a certain annotation on the composable function, then it can be previewed without running the application."

JetBrains considers developers of desktop applications to be underserved, a view partly informed by the company's own developer surveys. "Desktop is like a second-class citizen for many people... it seems like a niche which requires some attention."

Will JetBrains use Compose for its own tools? One of them, JetBrains Toolbox (which manages installed IDEs), already uses Compose, but Igotti said that there is too much legacy to expect it to replace the existing framework for products like IntelliJ IDEA. "The most complex and important component is the editor, it's been developed for 20 years and it's very unlikely that it will get rewritten in the medium term. It's not JetBrains or my goal to force everyone to write in Compose. Our goal is to give those who need a better framework a chance to use it."

We had a quick look at Compose for Desktop using the IntelliJ IDEA Community Edition and the basic tutorial: it all felt a bit bleeding edge, but we managed to get Hello World on the screen.

Does the world really need another cross-platform framework? Google's Flutter, though primarily intended for mobile, also now targets the desktop, as well as iOS, which Compose currently does not support. The language of Flutter is Dart, though, and although Dart usage is growing (primarily because of Flutter), it is still less popular than Kotlin, according to StackOverflow's latest survey.

There is evidence of momentum, with over 5,000 stars for the GitHub repository and plenty of issues being reported: developers should expect some snags but it is a sign of activity. Compose has a distinctive approach to UI building and perhaps the best way to look at it is that for those who have come to prefer that model thanks to using it for Android, the ability to target other platforms will be welcome. ®


Other stories you might like

Biting the hand that feeds IT © 1998–2021