Airbnb open sources MvRx, its Kotlin-first, Kotlin-only Android framework

Say hello to MvRx, Airbnb’s Android framework which aims to make Android screens easy to write [no matter their complexity]. Let’s have a closer look at it.
Choose Kotlin, not Java for a cleaner API
Last year, we asked if Kotlin can overtake Java for Android development and the answer seems to be yes.
First, this young programming language could “change how Java is used on the server, too. In short, Android developers without Kotlin skills are at risk of being seen as dinosaurs very soon,” according to the first edition of the new Realm Report. The report concluded that “Kotlin will overtake Java in December 2018.”
Second, Airbnb recently open sourced MvRx (pronounced “mavericks”), an Android framework that’s built “Kotlin-first and Kotlin-only.” Furthermore, in a blog post announcing the new tool, they mentioned:
Designing around the Kotlin language enabled us to build an API that is far cleaner than we ever could have achieved with Java.
MvRx builds on top of Google’s architecture components, RxJava, Epoxy.
SEE ALSO: Can Kotlin overtake Java for Android development? New report says yes
MvRx in a nutshell
Airbnb is using this new Android framework for almost all product development. Its goal is to make Android screens easy to write [no matter their complexity] and since it’s built on top of existing components such as Fragments and architecture components, it doesn’t constrain you and is easy to incrementally adopt.
MvRx is built on top of the following existing technologies and concepts:
- Kotlin
- Android Architecture Components
- RxJava
- React (conceptually)
- Epoxy (optional but recommended)
As exciting as this may be, you need to keep in mind that they are developing and maintaining the framework to support their needs. If you have requests concerning features, they might only consider the “demand” if it’s useful to them.
For full documentation, check out the wiki.
This is what MvRx looks like:
data class HelloWorldState(val title: String = "Hello World") : MvRxState class HelloWorldViewModel(initialState: HelloWorldState) : MvRxViewModel<HelloWorldState>(initialState) { fun getMoreExcited() = setState { copy(title = "$title!") } } class HelloWorldFragment : BaseFragment() { private val viewModel: HelloWorldViewModel by fragmentViewModel() override fun EpoxyController.buildModels() = withState(viewModel) { state -> header { title(state.title) } basicRow { onClick { viewModel.getMoreExcited() } } } }
Getting started with MvRx
Gradle is the only supported build configuration, so you’ll have to add the dependency to your project build.gradle
file:
dependencies { implementation 'com.airbnb.android:mvrx:0.5.0' }
For more information about MvRx, check out this blog post or head on over to GitHub.