I was thinking of building an app on Android with Scala instead of the regular Java (or the equivalent I guess). Is it worth it?
Any problems and unnecessary headaches?
Working with Scala should be mostly painless, as the dex compiler just works with bytecode - which is exactly what Scala produces.
Your biggest problem then is the dependency on scala-library, as dex expects everything to be in a single Jar. This is best handled with Proguard (which will also remove unused code and give you a smaller executable, ideal for mobile)
Current best practice is to use SBT with the Android plugin; It'll take care of everything for you: http://github.com/jberkel/android-plugin
If you must use Eclipse and the plugin supplied by Google, then you're going to have a non-standard directory structure. I also wrote an article on how to deal with this: http://www.assembla.com/wiki/show/scala-ide/Developing_for_Android
But be warned... it takes a lot more effort that way!
There is a talk by guys from bu.mp on Scala Days 2011.
Disclaimer: While they talk a lot about issues they've faced, the overall experience was definitely positive. Moreover, this were the problems of one particular team and they are minor ones.
Summary:
While he talks about IDEs too, I don't think that it is a problem (look this post, about Scala environment). Guys that do Scala IDE and IntelliJ do their work well and IDE support is getting better and better.
For unit testing one could use RoboSpecs (allows you to run unit tests inside JVM, not inside emulator), which is faster.
One of the biggest problems I've stumbled upon is the limitations of the dex format (no more than 65536 method references per dex file). Scala library simply doesn't fit into limits, so you have to workaround that by:
Some guys claiming that there are problems with IDEs, but things getting changed fast: the current version of the IntelliJ IDEA 12 not only has a good support of Scala as a plugin, but also contains UI Designer for Android. Moreover, you can use Eclipse which has a support from both Android (by Google) and Scala (by Typesafe) sides. Android Studio (the new IDE based on IDEA which was announced on Google IO '13 and is developed by Google) support IDEA plugins thus Scala.
We discussed this at Scala Lift Off London last Friday and the consensus seemed to be that it generally works fine as long as you avoid Actors. Also, the sbt-android-plugin was highly recommended. Nathan Hamblen's blog has many posts on Android and the ones also tagged Scala have a lot of gotchas worth looking out for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With