263

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?
Iamat8
  • 3,888
  • 9
  • 25
  • 35
Lemmy
  • 3,177
  • 3
  • 17
  • 16

9 Answers9

128

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

  • 3
    Thank you! I will have to try that out. I wonder if it can be used with Eclipse (using the Scala and Android Plugins) – Lemmy Apr 22 '09 at 19:28
  • 37
    Lemmy - is there any reason you didn't accept this answer? Perhaps you found a better solution? – Bostone Nov 13 '09 at 18:58
  • 3
    In my experience, treeshake isn't good enough for most nontrivial scala code. It's just not agressive enough. – James Moore Jul 16 '12 at 03:38
45

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

RamC
  • 1,287
  • 1
  • 11
  • 15
Jason Voegele
  • 1,918
  • 1
  • 19
  • 18
  • Works great! None of the solutions I tried worked out of the box but your Gradle plugin gave me useful feedback so I could easily fix what was going wrong. – Mendelt Aug 14 '11 at 15:16
  • Jason, are you still working on this? Last commit was 9 months ago and grade has been bumped versions since then. – Peter Ajtai Aug 17 '13 at 02:20
  • Peter, development has halted due to the fact that Gradle is now the native build system for Android. – Jason Voegele Sep 19 '13 at 15:50
22

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

Jan Berkel
  • 3,373
  • 1
  • 30
  • 23
  • 1
    This plugin is not compatible with newest versions of SBT. Are you still maintaining this plugin? An SBT plugin that *is* compatible with the newest versions of this the [android-sdk-plugin](https://github.com/pfn/android-sdk-plugin). – DCKing Aug 04 '14 at 10:44
19

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

Lukas Rytz
  • 1,894
  • 14
  • 27
15

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.

Community
  • 1
  • 1
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • 3
    This sounds awesome. How are build times with this solution when deploying to a device (compared to deploying a comparable Java Android project)? – evilcandybag Jul 12 '12 at 21:38
  • 1
    The build time is around 10 seconds when deploying to a device. I hope it will be faster someday. – Mikaël Mayer Jul 14 '12 at 11:57
  • 6
    It takes about 1 second now with the lastest android sdk and plug-in, because of some new good cache implementation. – Mikaël Mayer Oct 19 '12 at 13:23
7

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.

Community
  • 1
  • 1
DCKing
  • 4,253
  • 2
  • 28
  • 43
6

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.

pocorall
  • 1,247
  • 1
  • 10
  • 24
4

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/

mikowiec
  • 481
  • 7
  • 6
3

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.