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
Yes I think a discord channel for scala-android on the official scala server would be good, and at least eventually also a Gitter channel alongside the others. But it depends on if people are prepared to hang out there… but why not give it a try.
When we have decided what to do (?) I can make a PR. The “learning scala”-discord does not seem to be on that page, only the official discord. Community | The Scala Programming Language. It makes sense to add the whole server invite perhaps? And should there be a gitter channel on scala-android?
Not very sure about this one, it’s probably about if Google’s willing to support more of Java 8 or above, currently the whole class definition’s missing. Currently we’re just putting a slightly modified ClassValue.java copied from original OpenJDK source to patch it into the compilation.
Cannot say for sure without testing, but I think the log hints this probably is true. Typically when it hits the part and crashes the log looks something like this
W/.client.androi: Accessing hidden method Ljava/lang/invoke/VarHandle;->releaseFence()V (blacklist, reflection, denied)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Caused by: java.lang.NoSuchMethodException: java.lang.invoke.VarHandle.releaseFence 
Android explicitly notifies the method is blacklisted so it’s bit uncertain if catching NoSuchMethodException to route to the fallback will work if Android is just shutting down VM for trying to poke the method.
The hack was pretty minimal but packaging all the working stuff into a project must be something else, there are some difficulties with producing a clean minimal working project to be shared for following reasons -
As mentioned above, java.lang.ClassValue.java has to be patched in. This is normally just easy as putting a source file under src/java/lang, but there are more stuff to consider, because this doesn’t work if Gradle is running with JDK 9 or higher, due to newly introduced Java platform module system(JPMS) and we are yet to find a working configuration to actively patch with JDK 9 or higher so currently requires JDK 8 to work.
We currently are not using sbt but Gradle with the following plugin GitHub - dsvdsv/scala-android-plugin but the original repo is written and compiled with Java 11, which conflicts with the JDK8 requirement of above. This could easily be solved with porting the code to Java 8 and publishing for local.
Scala library itself also has to be patched for the scala.runtime.Statics.java mentioned above. However, this can’t be done with just putting it under the source file folder, but had to be done with making a small project to make a patched fat-jar of scala-library. Once patched and published for local this also was just good to go.
We’re happy to give out more details of the works as much as we can, please ask about any specifics you wish to know
Well, you already answered some of my questions. Thanks
Now the most important thing is - can you share the source code of your project? I work at https://wire.com where we still use Scala 2.11 for the Android client of our product. For sure we will not reuse your code or even update to a newer Scala version (which I find very saddening, personally, but well, too late to do anything about that) but it would be very interesting for me to compare what you’ve done with what I’m using at work.