Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for Scala 2.12 #334

Open
doofin opened this issue Jan 4, 2019 · 7 comments
Open

support for Scala 2.12 #334

doofin opened this issue Jan 4, 2019 · 7 comments

Comments

@doofin
Copy link

doofin commented Jan 4, 2019

what needs to be done?

@lhns
Copy link

lhns commented Jan 15, 2019

Sadly I have very little experience with the Android toolchain and how APKs are built but here are my thoughts:

The Scala 2.12 compiler outputs Java8 bytecode which cannot be directly compiled for Android using the current toolchain because the new bytecode instructions are not supported by the ART.
Android Studio uses a new toolchain based on the new D8 dexer which can desugar most Java8 instructions into Java7 bytecode, therefore being able to compile Java8 classfiles.
Retrolambda is currently used to do this, but if I understand correctly, the new D8 dexer should handle nearly all Java 8 features.
Also there is R8 which is D8 but with something like proguard included, which even accepts proguard config files.
Using D8/R8 would make retrolambda/proguard obsolete and sould be able to compile Java 8 bytecode and therefore Scala 2.12 to dex files. As far as I know D8 also handles multidexing automatically so there is a lot of potential for cleaning up obsolete code.
If we could use R8 in this project then I assume we could support Scala 2.12.

I made a small sbt plugin to test D8:
https://github.com/LolHens/sbt-android-d8
I was able to generate a dex file but I don't know what to do after that to generate an APK file.

Maybe someone more experienced with this plugin or Android development in general could comment on this?

@ihrimech
Copy link

Is there any news on this one ? We'd really love to hear some news on this one

@JulienSt
Copy link

JulienSt commented May 2, 2019

I googled a little bit and stumbled upon the following sites:
https://developer.android.com/studio/command-line/aapt2
https://elinux.org/Android_aapt
https://codeburst.io/how-your-android-code-compiles-to-deliver-apk-package-file-9f180129c9bf
https://jakewharton.com/androids-java-8-support/

The first two should give some insight for building APKs. I didn't try it, but this seems to be the way to do it. The last two links are just for further contextualization of how the whole process works (in case a new dev finds this issue and wants to help)

As a side note:
I started a thread on r/reddit to rally some help if anybody capable stumbles upon the topic. I thought spreading the word might help.
https://www.reddit.com/r/scala/comments/bip38h/potential_212_support_for_android/
I am also thinking about publishing it to something more android-related, but that depends if it is needed or not.

@Kright
Copy link

Kright commented Sep 13, 2019

New versions of android support java 8 (sdk 26 and higher). I have managed to use library written on scala 2.12 in android app (gradle project). It seems working on my phone with android 9.

@Kright
Copy link

Kright commented Sep 19, 2019

Unfortunately, this doesn't work :( The easiest way to reproduce - create gradle android project with minSdk 26, set java version to 1.8, enable multidex, add scala 2.12 std lib as dependency and try to call something like Option.apply(1). This fails in runtime with error "IncompatibleClassChangeError" even on android 9.

@shea-hawkins
Copy link

@LolHens
Thanks for the work on this. I'm digging into the code to find the build steps between Dex files and APKs. Usually Gradle handles this under the hood, but I've never been a fan of how heavy Gradle is for how presumably small a task packaging sources should be.

We may be either able to hook into the Gradle process shortly before packaging or replace the packager entirely.

@smarter
Copy link

smarter commented Apr 16, 2021

FYI, someone managed to get Scala 2.13 working with Android, see https://users.scala-lang.org/t/scala-2-13-on-android/7235 and their example project at https://github.com/androidscala213/AndroidScala213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants