Introducing MvRx: Android on Autopilot
The new framework for Android is fully native but eliminates 50–75% of product code.
At Airbnb, we are moving at a faster pace than ever. Each year, more and more people are using Airbnb to travel. This year alone, we have already launched Airbnb Plus and we have countless other projects underway that we can’t wait to share.
On the Android side of things, the astronomical growth of the business has kept us extremely busy. Our app does more than ever. In the past year alone, we have added 286 new screens and that pace shows no signs of slowing down. To make our lives easier, we look for patterns that we can use to prevent duplicating work which allows us to focus on shipping products.
Today, we are ready to share our Android architecture: MvRx. MvRx (pronounced “mavericks”) was born out of the recognition that we were solving the same problems over and over again, distracting us from focusing on shipping products. On Android, there are countless little things that engineers have to write or consider to make their app high-quality. Some of those are:
- Creating a layout with a toolbar, RecyclerView, and footer over and over again
- Wrangling with the Android lifecycle
- Properly saving view state and business logic in onSaveInstanceState
- Executing the onSuccess and onFailure handlers for asynchronous requests such as a network or database call
- and many more…
MvRx makes all of those and much more comically simple. When we set out, our only goal was to make it easier, faster, and more fun to ship a high quality product. Originally, open sourcing this framework wasn’t our goal. However, once it started to take shape, we knew that we had to do it. Not only do we want to share it with you but we also want it to be available for our own projects outside of Airbnb because it scales from hobby projects to an app with 70 engineers and nearly a million lines of code with ease.
MvRx in Action
MvRx builds on top of Google’s architecture components, RxJava, Epoxy. It is Kotlin-first and Kotlin-only. Designing around the Kotlin language enabled us to build an API that is far cleaner than we ever could have achieved with Java.
This is what it looks like:
In this simple Fragment, with just 18 lines of code, we have a ViewModel that is scoped to the Fragment but will be retained across configuration changes, as well as a default layout and a testable state for our screen. When the state changes, the screen will be automatically updated but only the specific parts that actually changed will be dispatched to the RecyclerView (thanks to Epoxy). Plus, all of the code you see runs on a background thread because MvRx handles threading seamlessly out of the box.
MvRx at Airbnb
In just a matter of months, MvRx has gone from a pilot to the standard way we write nearly 100% of new screens and people are loving it. In the most recent survey, 93% of the engineers surveyed (n=14) gave it an 8/10 or higher.
In addition, its adoption has been astounding. Growth was steady through the pilot but when we opened it up for any team to use in July, adoption took off on its own.
In just a few months, we have built over 110 screens in MvRx and it has quickly been adopted as the go-to way to write any feature from a simple static feature to some of the most complex features in our app.
We’re excited to be sharing MvRx with the world. If you want to learn more, head over to our GitHub Wiki to learn more!
Airbnb Mobile Engineering
Want to get involved? We’re always looking for talented people to join our team!