Developing Android applications with Scala can be fun and rewarding. the code will be cleaner and simpler than the equilvant Java code. To get started, we need to install a few things. First off, the Java 6 JDK needs to be installed.
Go to http://www.oracle.com/technetwork/java/index.html and select Java SE 6 Update 43 JDK or just go http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.html
If you are on a Mac just type javac into a terminal to download java6 from apple.
Just follow the instructions and prompts from the java installer.
You have to use JDK 6 Android will not work if compiled with JDK 7.
export ANDROID_HOME=~/android-sdk
export ANDROID_NDK_HOME=~/android-ndk
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_NDK_HOME:$PATH
Now we have the basic android tools installed. We need to install the platforms
$ android
Place a chehckmark next to “Android 4.0.3 (API 15)”. This is Ice Creame Sandwitch version of android. I would select any other versions you wish to target as well. Click the Install Packages button to download the platforms. You will be asked to accept the licences.
Now that we have the platforms installed, we need to create a virtual device. Android comes with a tool called the avd manager. To start the manager you type the command below.
$ android avd
With the manager up, we can start creating the avd.
export SCALA_HOME=~/scala
export PATH=$SCALA_HOME/bin:$PATH
export SBT_HOME=~/sbt
export PATH=$SBT_HOME/bin:$PATH
$ java -jar conscript-0.4.1.jar
$ curl https://raw.github.com/n8han/conscript/master/setup.sh | sh
$ cs n8han/giter8
This gives us the g8 command for our templates we will use to create the projects.
For our development we are using InteliJ IDE with the scala plugin. Also we are going to use an SBT Plugin to add ide project config generation to the tool chain.
Open the plugins file under the .sbt directory in the home directory. If it’s not there just added it.
$ vim ~/.sbt/plugins/build.sbt
Once we have the file open we need to add this line below:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0")
The next time we run sbt it will download this file and have the command available to any project.