Scala on Android
This is a repo for examples, small tutorials, and some chaotic notes on how to write Android apps with GraalVM, Gluon Mobile, JavaFX, and Scala. As you can imagine, even putting this whole tech stack together requires some effort. But I managed to do this pretty quickly for something that looks so complex, so I decided, why the hell not, I want to share with you how to do it. My idea is to test all the usual functionalities an Android app should have:
- UI widgets [done]
- Push notifications
- Web sockets [done]
- Access to the camera and microphone
- Android's KeyStore (e.g. for storing encrypted passwords)
- Intents from other apps (e.g. for file sharing)
- The app lifecycle, esp. how to manage going to the background and waking up, receiving an event while in the background, etc.
- Permissions [done]
- Execution contexts handling [done]
If any of them don't work and there are no easy alternatives, it means the whole tech stack is not mature yet. But from what I saw so far I'm carefully optimistic. Especially the fact that so many people work on so many parts of all of this, and my work consists mainly of putting it all together, gives me hope.
My goal for further future (overly optimistic, of course) is to write a TRON game where players could log in to a server, set up a board, play a game with each other (or maybe even three or four people together) and store the history of their games on the backend. For that I would either use FXGL or libGDX. But that's in a galaxy far away.
So, are you ready to try?
If you're like me and before you start anything you need to know its history and context down to the times fish crawled out of the primordial sea - here's an overview of history of Scala development on Android and its current status as of 2021.
Here's a tutorial on how to build an Android app in Scala
And here are the examples:
- HelloFXML - the simplest one, and my "go to" example for debugging any build system issues
- HelloFXML 3 - same as above, but in Scala 3
- HelloScala - another minimalistic example
- European Union - shows a scrollable list with country flags downloaded from Wikipedia and some basic Android GUI functionality
- European Union 3 - as above, but in Scala 3
- Comments - an app showcasing a bit more complex GUI functionality; thanks @rleibman!
- Calculator - well, it's a calculator
- HelloFXGL - a minimal example with FXGL, a game engine; for now works only on desktop
Discord
There is a #scala-android channel on the official Scala discord: https://discord.gg/UuDawpq7
I write there mostly about the GraalVM stack, but if you're interested in React Native+Scala.js approach, you're more than welcome (actually I need someone to write about that :) ) or if you're into the sbt-android or gradle-scala plugins, or maybe you don't even care that much about Scala but you're interested in one of the other puzzle pieces we can use: GraalVM, Gluon Mobile, Slinky... come and share your ideas :)