We currently are extensively using Scala to build our app and had to go through some tricky situations to make Scala 2.13 (or Scala 2.12.8 and higher) on android to happen, addressing the following issues
Currently Android’s support on JVM 8 and above isn’t perfect, missing ClassValue.java from its package. We had to write own java.lang.ClassValue.java that mimics the behavior to get through it
Access to java.lang.invoke.VarHandle.releaseFence() is currently blacklisted on Android, which frequently used by immutable collection classes. We had to modify scala.runtime.Statics.java to do nothing to keep it away from trying to access the method
Since currently android only supports MethodHandle.invoke() for API version 26 or higher, we had to set minSdk version to 26
We managed to compile and run our app on Android with Scala 2.13 by troubleshooting the issues above and pretty satisfied with the result.
Will there be any plans to make it easier to deploy Scala on Android in the future? We’d love to keep Scala going for building our App for coming years.
That’s really interesting, it seems that you’re the first to manage to run a recent Scala on Android (without using graal native or a different backend), very cool!
I don’t think that can be worked around from Scala’s side without breaking binary compatibility, is there an Android bug report about this?
Looks like Statics already has a fallback on sun.misc.Unsafe#storeFence if the VarHandle class is not found: scala/src/library/scala/runtime/Statics.java at 889d5c685f4e3c2ae399d861a7afad438c187ab1 · scala/scala · GitHub, it seems that in Android the class exists bu the method doesn’t, so maybe we just need to do catch (ClassNotFoundException | NoSuchMethodException e) in that first catch clause, if that works I would encourage you to send a PR with that change.
Hi,
I’m always happy to write something.
I think maybe my original blog entry can be made into a guest post? Scala on Android – Making the matrix
but if you prefer something different (more technical?) I’m open to suggestions.
@makingthematrix Yes, I think either your post or William’s post could be the basis of something for the Scala blog, once it was updated to discuss not only the GraalVM and Scala.js options, but also the new one @onsq has pioneered, with pros and cons to help the reader choose.
I think an ideal blog post would probably be pretty high level and not super long, but it would include links to more detailed resources covering all three options.
So you are able to use Scala 2.13 with Android SDK? Wow. That’s interesting. In my work at Wire I’m stuck with Scala 2.11 (because we still support older Androids). Recently I talked about this on ScalaLove (there’s a link in previous comments ). Right now I think that trying to work with Scala on standard Android SDK is too much hacks and an uneven fight with Google, so I look more into GraalVM and/or React Native + Scala.js. But it’s very good to know that someone is trying
From what I understood it required a lot of troubleshooting.
When I said the naive thing I meant exactly that. Create an sbt project, add sbt-assembly, write some code, execute sbt assembly, install the uber jar, and that is it.
Of course, it is very exciting to see that, even if with some caveats, we would have a more “natural” of creating Android apps using Scala than using GraalVM or Reac Native.
@SethTisue for greater clarity the discord server @bjornregnell has linked is NOT a dedicated discord for Scala android. Its a discord server setup by @leobenkel to help people learn and get better at scala. The Android channel is one of the newer channels added to it. Join it! Its a cool discord.
Yes. I asked Leo to create it just a week ago. I’m going to post there links to blog notes and example apps I’m making. So far I got a few questions, and - before the channel was set up - one person made a Scala app based on an example in Java. I hope more will come