Scala Programming for Android

AndroidScalaResources

Android Problem Overview


I have followed the tutorial at Scala and Android with Scala 2.7.3 final. The resulting Android App works but even the most basic application takes several minutes (!) to compile and needs 900 kb compressed, which is a show stopper for mobile applications. Additionally, the IDE runs out of memory every now and then. I assume dex is not made for big libraries like the scala-library.

  • So my question is: Has anyone actually done this and is there any cure for this?

Android Solutions


Solution 1 - Android

I've written some basic Android applications in Scala, nothing too epic. Not being a Java programmer I was suggested to use a "treeshake", I was explained by a friend that this strips out all the unnecessary libraries from the jar files.

I have not documented it, but I found that someone else already has:

http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html

Proguard is not the only solution, you might find something that suits your work flow or is more suited for your environment.

Additionally google have just realised JACK , which deals with quite a lot of reducing build and memory times see https://source.android.com/source/jack.html

Solution 2 - Android

You can now use the Android plugin for Gradle to create Android applications in Scala. It incorporates the ProGuard tool to trim the fat from the resulting APK file, so seems to meet your needs.

https://github.com/jvoegele/gradle-android-plugin/wiki

Solution 3 - Android

There is also an plugin for the Scala-based builder sbt: sbt-android-plugin.

Solution 4 - Android

For tutorials and examples, see also Stéphane Micheloud's "Exploring Android" page: http://lamp.epfl.ch/~michelou/android/

Solution 5 - Android

I verified this detailed solution with Eclipse 3.7, Scala 2.10 and the plug-in AndroidProguardScala v50:

https://stackoverflow.com/a/11084146/1287856

Everything works fine. A simple test application with scalafied main activity class only takes 38Kb. Libraries projects are supported. Proguard is activated when exporting the project.

Solution 6 - Android

Developing Android apps for Scala is continuously evolving. The current best way to do it appears to SBT in conjunction with the android-sdk-plugin, which is maintained* and works well for me in my Scala/Android project. A somewhat recent example that demonstrates the use of this plugin with the already mentioned Scaloid can also be found.

Please note that this question is a typical example of a question with outdated answers on Stack Overflow. This answer will likely become outdated at some point as well.

* The other SBT based projects mentioned in this answer thread don't appear to have code being written for them in the last six months at the time of writing. They may have compatibility issues with newer versions of Scala and SBT.

Solution 7 - Android

If you use maven, use android-scala-test as a startup template. It works great for me out-of-the-box.

Scaloid is an Android API wrapper written in Scala that help you to write your Android program in Scala-style.

Solution 8 - Android

You can use the Scala on Android without SBT, it built externally by Gradle to create Android applications. https://github.com/yareally/android-scala-intellij-no-sbt-plugin

Gradle is more native building tool for android than SBT.

There is good example of Scala client and server side solution concept, and gradle building tool as advance for IntelliJ IDEA workbench.

Big advance that core classes are common for client and server.

https://github.com/ghik/akkdroid

Good tutorial for IDEA and android-plugin: http://fxthomas.github.io/android-plugin/

Solution 9 - Android

The biggest issue with Scala on Android is the compile times.

Possibly because of the Proguard class stripping compiles with IDEA13/Scala plugin on a Dual Quad Core (8-CPU) E5450 Xeon with 8GB can take two minutes or more.

I simply moved back to Java after completing a largish Scala Android project as compile times were too frustrating.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLemmyView Question on Stackoverflow
Solution 1 - Androiduser75240View Answer on Stackoverflow
Solution 2 - AndroidJason VoegeleView Answer on Stackoverflow
Solution 3 - AndroidJan BerkelView Answer on Stackoverflow
Solution 4 - AndroidLukas RytzView Answer on Stackoverflow
Solution 5 - AndroidMikaël MayerView Answer on Stackoverflow
Solution 6 - AndroidDCKingView Answer on Stackoverflow
Solution 7 - AndroidpocorallView Answer on Stackoverflow
Solution 8 - AndroidmikowiecView Answer on Stackoverflow
Solution 9 - Androiduser2476398View Answer on Stackoverflow