Sunday, 19 September 2010

Converting Meditation Helper to Scala: I Hate Ant. And Eclipse.

I hate Ant. I really do. So much that I decided to revisit my strategy for this project. At first I tried to configure Maven, but that proved really difficult. I like Maven a lot, but the combination of the Android plugin, the Scala plugin, and the Proguard plugin seems really difficult to configure at the minute.

And so I have revisited sbt. I now have a working build using sbt. The next problem is to integrate that nicely with an IDE. I have tried to make this work well with Eclipse but, well I may as well say it - I hate Eclipse. I really do.

So where am I - sbt works well, and is probably the simplest solution for building an Android project in Scala. The Eclipse Scala plugin is a bit flaky. So - I've read good things about Intellij. The community edition will do Scala via a plugin. It won't do Android, but that's fine - I can handle all the Android stuff either from the command line or using sbt. All I need is a good Scala editor.

I will use to create the project files for Intellij. Fingers crossed...

Well that went very smoothly. After a weekend of wrestling with Eclipse, could I have found a winner in Intellij??


It has taken me all weekend. I have torn out most of my hair. But I now have a working development environment to re-write my app in Scala. I am using:
  • Scala 2.8.0
  • Sbt 0.74
  • JUnit 4 
  • Intellij 9.0.3
All builds etc are run through the sbt console. I only use Intellij for it's Scala editing capabilities, with Android added as a standard jar library. Any Android stuff I can do directly using the tools from the command line.

Hallelujah. My work here is done. Now I can really write some code.


Monday, 13 September 2010

Converting Meditation Helper to Scala: Creating the Scala Project

Now that I have managed to install both the Scala IDE and Android plugins into the same instance of Eclipse, the next stage is to create a new Android project for the Scala version. To do that, I'm going to use the Android plugin for sbt, described at
  • First things first - I need a version of Scala installed outside Eclipse. I will use the IzPack installer from
  • That was easy. Once it was installed all I had to do was add the ~/scala/bin directory to my PATH.
  • Now to follow the instructions at zegoggles to install sbt.
  • All seems good so far. Now to generate the project using the android-plugin listed on that page, and the instructions.
  • ../android-plugin/script/create_project MeditationHelperScala com.nwalex.meditation.scala --api-level 7
  • I've used a different package name so that I can install this version side by side with the current version on my phone. I will need to change this before I deploy the new version to the market.
  • Ah, that worked well but doesn't have Eclipse integration. 
Let's try another approach.
  • Using the instructions at I...
  • Created a new Android project in Eclipse using the wizard.
  • Created the Ant files using: android update project --target 1 --path .
  • Followed the directions to customize the ant file and the rest of the instructions and...
  • IT WORKS!!!
To stop Eclipse and Ant getting in the way of each other, I changed the so that the Ant generated classes go into gen-ant, and builds into bin-ant.

With the external build tool configuration I can now edit the files in Eclipse using the Scala perspective, and run ant to do the build and install to the emulator.

Now I can get cracking with the conversion.

Sunday, 12 September 2010

Converting Meditation Helper to Scala: Configuring Dev Environment

Now that Meditation Helper is fairly mature, I have decided to do a complete re-write in Scala. There are 2 reasons for doing this:
  1. The current code is a bit messy. Since I was learning how to develop for Android while writing the application, I made some mistakes early on that are making it difficult to add new features in an elegant way. I want to fix those mistakes.
  2. I want to learn Scala.
If it were possible to write Android applications in Clojure, then I would use Clojure. However, it appears that the dynamic nature of Clojure makes it impossible to run on Dalvik, since Dalvik is not Java (despite what Oracle thinks). It seems that Scala does not have this problem. It is a statically typed language that compiles directly to byte code.

I am going to record my progress here. I have no idea how it will turn out.

I intend to create a brand new Android project, then copy across the various resource files (GUI layouts etc). The new version will therefore look exactly the same as the Java version, and will use the same database tables to read from and write to. So the front end and back end will remain the same, with everything in between re-written in Scala.

Once I have a fully working version of the app written in Scala I want to compare the performance and the size of the package.


  • Ok, that's not a great start. I just tried to install the Scala IDE from The installation seemed to go ok, however, it seemed to wipe out the Android plugin! The app wouldn't compile because the builders had disappeared. So, having reverted to a previous version of my .eclipse directory, I will try again by creating a new workspace, and installing the Scala plugins. Then I will switch back to the old workspace and check whether or not the app will compile.
  • The Scala plugin really doesn't seem to want to install. Downloading Eclipse Classic 3.5.2 to try with a fresh Eclipse installation.
  • That seemed to work. To be fair it does say at that Eclipse Classic is a requirement. I was running one of the other Eclipse builds - Eclipse for Java developers I think. Now to re-install the Android plugin.
  • Had to add to the list of update sites in Eclipse in order to resolve the Android dependencies. And even then it still doesn't work. Now neither Scala or Android appear to be available. This is turning into a yak shaving exercise.
  • Woo hoo! I had the wrong version of Eclipse classic - 3.5.0 instead of 3.5.2. 
So in summary, to have Scala and Android pluging in the same IDE I needed to:
  • Install Eclipse Classic 3.5.2
  • Add to the list of available download sites
  • Add to the list of available download sites and install the Scala IDE
  • Add and install the Android plugins.
I hope things go more smoothly from now on...