In this episode, I get Realmʼs Kotlin Multiplatform sample app running on Android and iOS.
Welcome to another episode … of Touchlab Touchpoints…
Iʼm Justin Mancinelli.
[Realm Kotlin First Commit, Dec 2019]
Itʼs been a long time in the making, but the Kotlin version of Realm is out,
and it comes with a delightful surprise…
Itʼs not just Kotlin…
itʼs Kotlin Multiplatform
Realm started as a lightweight NoSQL database for embedded systems in 2010
It became very popular on mobile very quickly after the Realm Mobile Platform launched in 2016
Now, I started my career as a backend dev around 2010.
That was a time of big shifts in database technology, or, at least peopleʼs acceptance of new database technologies.
Within just a few years, we saw the rise of the likes of MongoDB, Redis, and Cassandra running on servers, ushering in an era of big data and web scale applications.
To me, the frenzy around Realm in 2016, looked similar to what I saw happening on the backend not long before
[Future of Crossplatform is Native]
As it turns out, 2016 is in the middle of the trend towards native multiplatform technologies which I described as the Modern Era of Computing in my 2019 talk The Future of Cross Platform is Native.
Was it just coincidence that Realm launched a native SDK for Android and iOS in 2016, or was it part of a trend? Either way, it was fortunate timing for Realm, and for mobile application developers.
While Realm was riding the native mobile wave, MongoDB was losing developer interest.
[MongoDB search trend peak between 2015 and 2017]
Between 2015 and 2017, search trends for MongoDB stagnated and began a descent
[Announcing MongoDB Stitch 2017]
Recognizing Mobile being a gap in their product offerings, MongoDB announced Stitch Mobile in 2017 Stitch Mobile allowed mobile applications to synchronise with MongoDB instances running in the cloud
But that wasnʼt good enough, and by early 2019, they had released Mobile Sync for Android and iOS allowing mobile apps to access a locally embedded version of MongoDB
I donʼt know how long acquisitions take, but I find it very interesting that a mere 3 months after announcing Mobile Sync for iOS, MongoDB acquired Realm.
Presumably, theyʼd been in talks for longer than 3 months and they continued developing and releasing Mobile Sync in case the acquisition fell apart.
But thatʼs pure speculation my my part so Iʼll stop talking about that.
Instead letʼs talk about unifying code across platforms
The first few hints of MongoDBʼs code unification strategy became visible soon after the Realm acquisition
During MongoDB World, in 2019,
MongoDB CTO Eliot Horowitz and Realm Co-Founder Alex Stigsen spoke about the their plans for Realm at MongoDB
With a title like “MongoDB Realm unifies mobile, web, and backend development” you know theyʼre being serious about it
I noticed they had already done work to unify the architecture patterns across the Stitch iOS, Android, and Web SDKs, so I asked Elliot if they planned to unify their SDKs through shared code, and, of course, I suggested Kotlin Multiplatform as a good fit.
He responded, “Yes, unifying the code is the plan… as well as greatly improving Kotlin support”
The proof that this was not just talk and empty promises came when Realm spoke at Driodcon APAC at the end of 2020
And, with the recent publication of the JetBrains case study it’s now official!
Itʼs funny that iOS isnʼt mentioned in the JB Post…
And not in the repos README either…
I needed to know whether they were touting Kotlin Multiplatform but only supporting JVM and Android targets like, so many KMP projects do.
But I did find the sample app that includes iOS in the repo…surely they wouldnʼt have that there if it didnʼt work… Only one way to find out…
First thing to note is they only support x86_64 and arm64… they spell that out, but of course I didnʼt read so ran into issues until switching to an x86_64 emulator. Donʼt waste your time like I did.
I ran the Android configuration straight from Android Studio and it worked nicely. The app isnʼt anything to write home about, and the whole point was to see this running on iOS, but … smoke test complete … it works on Android!
Their sample is based on the JetBrains sample which recommends installing the KMM Plugin for Android studio, but I didnʼt have it installed and wanted to see results fast
Being familiar with Touchlabʼs KaMP Kit, I opened up the terminal and ran ./gradlew build
[iOS Release Builds not supported]
Second thing to note is they donʼt support Release builds for iOS yet… I tracked down an issue to figure that out. Again, donʼt waste your time like I did.
Once I built the debug framework, I was able to open up Xcode, run the build, and there I saw it … the sample app … running in my iPhone simulator … persisting data … in Kotlin Multiplatform Realm.
[ME] So, yay! It works!
Will this revitalize MongoDB and Realm?
I have no idea, but Iʼm super excited
Iʼm also very happy that they put in the effort. It was definitly worth the wait.
If you are trying out Realm in your Multiplatform Mobile app, reach out to Touchlab, weʼd be interested in chatting privately … or publically if you are up to it.
Thank you for listening.
And remember to subscribe to hear more … Touchlab Touch Points.