A template project in Scala 3 for the latest Android Studio translated from Java.
Android Studio is currently quite opinionated towards Kotlin,
so a Java module is not an option you get in the New
> New Project…
menu.
If you want to use Scala 3 together with Kotlin, starting from the standard Kotlin template, please check https://github.com/mcallisto/Scala-3-Android-Studio-Kotlin-template.
Helping the adoption of Scala in Android Studio.
This is the Scala project you get if:
-
in Android Studio Meerkat Feature Drop | 2024.3.2 you create an
app
module with the Fragment + ViewModel template. -
you then add a minimal Scala 3.7.0 module named
core
and call it from theapp
module -
you use STTP to query ScalaDex and display the results. Credits and big thanks for this to @keynmol
-
you translate to Scala the activity, fragment and model Java code in the
app
module
Because is the first Scala version shipping scala/scala3#22632. The emitted Scala code is more compatible with Android ART.
Since currently all Scala libraries are not yet published to Maven Central with this version,
the workaround is to let Android R8 minify the code,
so minifyEnabled true
must be set even for debug
builds.
In this project two different solutions coexist:
-
The
app
module is built using the scala-android-plugin, which is brilliantly designed to work with the official Android Gradle Plugin (AGP). -
The separate
core
module is built with the official Gradle Scala Plugin, which is not compatible with AGP.