7 things you should know before using Jetpack Compose

Jetpackcompose-bloco.png

Jetpack Compose is the latest Google bet on a modern UI toolkit for Android Development. It promises to build native UIs with less code and with less developing time than previous toolkits.

Declarative frameworks have been winning traction in the development world. The people at Section wrote a nice article on what is a Declarative UI (code). And how does it stand against Imperative UI (view-based).

But before you dive into Jetpack Compose, we've compiled a few important things to know.

 

7 things you should know

  1. Is it production-ready?
  2. Can I use it with Java?
  3. What are the minimum requirements?
  4. How does it effect Performance, Build Time and APK sizes
  5. Can I use it in existing Android projects?
  6. How well does it integrate with other Android best practices?
  7. Is it multiplatform?
 

1. Is it production-ready?

Googles launched Jetpack Compose 1.0.0 and said:

"It's stable, and ready for you to adopt in production."

We won't say otherwise, but do note that only using Jetpack Compose on a bigger project may result in a lot of refactoring. At the moment there's still some experimental APIs for standard development practices.

 

2. Can I use it with Java?

Jetpack Compose is Kotlin exclusive. It uses features such as coroutines, and the handling of @Composable annotations is done by a Kotlin compiler. There is no way to get access to these from Java. So if your project does not support Kotlin yet, you can't use Jetpack Compose.

 

3. What are the minimum requirements?

Jetpack Compose was made with interoperability and integration in mind. Still, you should know the following:

  • Minimum API level – At the moment its not possible/advised to use Jetpack Compose on any OS below Android 5.0 Lollipop (API 21).
    • At the time this article was written, minimum API 21 is estimated to support 94.1% of all android devices in world.
  • Android Studio Arctic Fox (2020.3.1) – For the best experience possible you should use Arctic Fox, because it comes with a lot of features that will enhance your experience.
  • Android X – To use Jetpack Compose you need to migrate to the AndroidX namespace, if you haven't done so yet.

Other notes:

  • Material Design – You can customize Compose's implementation of Material Design, if that doesn't suit your needs, you can build a custom design system using Compose's public APIs.
 

4. How does it effect Performance, Build Time and APK sizes

Google claims that Compose saves time and it has better performance than the traditional view systems. To prove this they tested with a few applications:

  • Tivi — has made a complete migration to Compose, and you can find more information about the migration at this link.
  • Sunflower (compose_recyclerview branch) - adds compose to replace the traditional RecyclerView.

Google also has a more in-depth look at these cases at their website. But below you can find a visual representation of the APK size and Build Time changes in both cases.

 
 

5. Can I use it in existing Android projects?

Yes! Jetpack Compose was made to be completely interoperable.

"Jetpack Compose is designed to work with the established view-based UI approach."

There are two main ways you can integrate Compose with a view-based UI:

  • Adding Compose elements into your existing UI
  • Adding view-based UI elements into your composable functions.

If you are building a new app you may just use compose. But for those who are planning on migrating, rest assured that you can do it step-by-step, feature by feature. It's even Google's advice:

"Migrating the entire app to Compose is best achieved step by step with the granularity the project needs"

 

6. How well does it integrate with other Android best practices?

Compose was built with integration in mind and is able to integrate with every other Jetpack library.

Untitled3.png
 

Besides Jetpack libraries its also easy to integrate with other major and modern libraries, like:

Jetpack compose shouldn't limit any library you know. The question is whether or not that library will still make sense. And how to use it with compose. One library we usually recommend using is Epoxy, but with Compose it is no longer required.

 

7. Is it multiplatform?

With Jetpack Compose Multiplatform it's possible to use the same declarative approach. And APIs used for modern Android applications for desktop and browser apps. These are powered by Kotlin on the JVM and Kotlin/JS for the web.

But when this article was written, Jetpack Compose multiplatform support was in Alpha stage. So it's not production ready for:

  • Desktop (Compose for Desktop)
  • Browser (Compose for Web)

Also, there is currently no support for iOS.

 

Should I use Jetpack Compose on my next Android project?

It depends, as always. As with most technologies and development choices, there's no one tool to solve all problems.

If you are starting a side project you should definitely give it a try. And learn what might be the future of modern Android development.

If you are in a rush or deadline it might be more risky than its worth. You will need to re-learn how to build basic UIs and how to properly make them scale with your codebase.


At Bloco, we are currently developing small projects with Jetpack Compose. We want to experiment with it so, soon we will write in-depth about our findings. Follow us on Twitter to make sure you won't miss it.