Developing for Android

Status Quo

  • Android applications are self-contained, there appears to be no way for users to deploy a shared library to a device.
  • The Scala library therefore needs to be embedded in every Android application that uses it.
  • The Scala nature can be successfully added to an ADT project.
  • Using ProGuard is highly desirable, to keep these apps to a manageable size.

Prerequisites

  • You have installed Eclipse, the Android SDK, and ADT.
  • You have been able to deploy a Java application to an Android device (physical or virtual).
  • You have installed the Scala-IDE that matches your version of Eclipse.

Step 1: Install AndroidProguardScala

(Collect underpants.)

AndroidProguardScala is an Eclipse plug-in that automates the process of determining the parts of the Scala library your application needs, creating a .jar, and including that in your .apk file. It is written by James Moore and maintained at https://github.com/banshee/AndroidProguardScala. You should follow the directions in the README to add the plug-in to your Eclipse installation.

Step 2: Enable Scala and AndroidProguardScala

(???)

  1. Open an Android project.
  2. Right-click the project and choose Add Scala Nature (which may be under the ‘Configure’ sub-menu).
  3. After a successful build, right-click the project and choose Add AndroidProguardScala Nature.

Step 3: Develop for Android using Scala

(Profit!)

You can now use Scala or a Scala/Java mix to develop your Android project. Builds occur normally, either in the background or on-demand, through the normal Eclipse machinations. You can use the Run menu to do testing and debugging just as you could before you enabled Scala. As an example, here is the Android application generated by ADT rewritten in Scala:

package com.example.helloandroidscala

import android.os.Bundle
import android.app.Activity
import android.view.Menu

class MWTApp extends Activity {
        override def onCreate(savedInstanceState : Bundle) : Unit = {
                super.onCreate(savedInstanceState)
                setContentView(R.layout.activity_main)
        }

        override def onCreateOptionsMenu(menu : Menu) : Boolean = {
                getMenuInflater().inflate(R.menu.activity_main, menu)
                return true
        }
}

Feedback

This guide is managed through in the Scala IDE documentation project on github. Please use github tickets and pull requests system for feedback.

Updated to use AdroidProguardScala by Boyd Stephen Smith Jr. - +Boyd Smith @DaTwinkDaddy; based on documentation written by kev.lee.wright and other wiki contributors.