##Usage
Requires sbt and the Android SDK (brew install sbt android-sdk
when using homebrew on OSX).
Using a giter8 template is the easiest way to create a new project that uses the plugin. If you don't have giter8 installed:
$ curl https://github.com/n8han/conscript/raw/master/setup.sh | sh
$ ~/bin/cs n8han/giter8
Now create a new project with one of the Android templates:
$ ~/bin/g8 n8han/android-app
This will prompt you to customize a few values (press enter to accept defaults), then create the project structure and all needed files plus skeleton tests, specs and activities.
To build the package:
$ cd <your app name>
$ sbt # enter sbt's interactive mode
> update
> package
To install and start the main activity in the Android Emulator (must already be running):
> start-emulator
To build a signed package for release into the Marketplace:
> sign-release
##Scala Versions
The version of Scala that sbt compiles your project against is
configured in the buildScalaVersion
property in the
project/build.properties
file. You can set this to any Scala
version.
Whenever you change build versions, you'll need to run update
again
to fetch dependencies. For more information, see the sbt documentation
on cross-building.
##Typed resources references
As an enhancement to the Android build process, this plugin can
generate typed references to application layout elements. To enable,
mix the TypedResources
trait into your sbt project
definition. During compilation a file TR.scala
will be generated
under src_managed/main/scala
.
Typed resource references are created in an object TR
(similar to
Android's standard R
). These are handled by the method findView
defined in the traits TypedView
and TypedActivity
. There are also
implicit conversions defined in the object TypedResource
; import
these to add the method on demand to any views and activities in
scope. The findView
method casts the view to the known resource type
before returning it, so that application code can avoid the redundancy
of casting a resource to a type it has declared in the resource
definition.
Since Android's resource IDs are scoped to the application, a warning is issued by the plugin when the same ID is used for different types of a resources; the type of resources retrieved by that ID will be unpredictable.
##Hacking on the plugin
If you need make modifications to the plugin itself, you can compile and install it locally (you need at least sbt 0.7.x to build it):
$ git clone git://github.com/jberkel/android-plugin.git
$ cd android-plugin
$ sbt publish-local
Because the plugin gets cached in a project based on its version
number you might need to use sbt clean-plugins
to force a reload
after sbt publish-local
.
##Credits
This code is based on work by Walter Chang (saisiyat), turned into a plugin by Mark Harrah.