32

I've started learning Scala, and I... I think I'm in love. I've only coded small test snippets so far, but since I currently working in Android development, what I really want to do is try my hand at writing Android applications in Scala.

I've found articles and questions on the matter, but mostly referring to older versions of the three tools (Android SDK/Scala/Eclipse), so the general question is:

Is anybody coding Android apps in Scala right now, with the latest SDK, Scala 2.9 and Eclipse Indigo? How viable is it?

And, in particular:

  1. How's the interaction/integration between Scala's features and the Android library?

  2. What's the state of the Scala plugin for Eclipse? I've read all the features you'd expect are there, but I'd like to know first-hand stories, specially about the debugger.

  3. How well does the build process (scala to java to dalvik, ant, proguard, etc.) automate?

Thanks!

salezica
  • 74,081
  • 25
  • 105
  • 166

4 Answers4

8

We are using Scala heavily to test our Android code - you can read a writeup of how we're doing so here. We use Ant or SBT to compile - there's an excellent SBT plugin for Android development.

Having said all of that, I'm not sure that I would recommend Scala for production Android development. In particular Scala 2.9.x is basically unusable as there is no good way to get the libraries to work on Android. You can read about the issue here.

It's a real pity, as Android development would benefit considerably from Scala if we could get it working properly.

Paul Butcher
  • 10,722
  • 3
  • 40
  • 44
  • 2
    I'm programming with scala 2.10 with the AndroidProguardScala plugin on eclipse (see below). Scala can be recommended for android development. – Mikaël Mayer Oct 19 '12 at 13:21
4

Solution found here to use the latest Android SDK, with Eclipse 3.7.2 and Scala 2.9 :

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

  1. It completely handles the android library
  2. You can make Android Library out of scala projects as usual
  3. The build process is completely automated, including proguard-ing and exporting the project with the regulard Android tools.
Community
  • 1
  • 1
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • Strange but true, from some day I cannot launch android applications built with `scala 2.9` (`2.9.3 RC1`, to be precise) no more, because I get `NoClassDefFound` at runtime, although the corresponding classes are indeed written into `classes.dex`. But more recent `scala 2.10.0` works almost fine (at the moment, there are some strange incompatibilities with android, for example `"".format(...)` method generated bytecode that android cannot understand correctly – Display Name Feb 01 '13 at 04:34
  • Me too. I don't know why. I have arleady switched to scala 2.10 – Mikaël Mayer Feb 02 '13 at 07:02
3

This video from ScalaDays 2011 may be hepful:

Scala on Android: Real-world Experience at Bump Technologies by Michael Galpin

EDIT:

If you really really want to run Scala code on Android (and not really make an app, but for yourself), then I have an easier solution. It depends on if your phone supports the procedure. In summary the steps are:

  1. Install Ubuntu on your device (as described here). This will not affect the Android installation.

  2. Boot Ubuntu, install JDK, Scala, etc, copy your Scala jars and run from there.

Jus12
  • 17,824
  • 28
  • 99
  • 157
3

I started to implement the android application (a twitter client) from the book "Learning Android" with Scala 2.9.0-1 a while ago.

In my opinion you can use it. I had only one problem with the parameter list at AsyncTask (see this link, problem #3). If you want to checkout out the project, you can find it here.

Christian
  • 4,543
  • 1
  • 22
  • 31