##Usage
Requires sbt and the Android SDK (brew install sbt android-sdk
when using homebrew on OSX).
Also note that this plugin requires the 0.7.x release of sbt - it has not been ported to 0.10 yet (cf. issue #50).
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:/raw.github.com/n8han/conscript/master/setup.sh | sh
Directory name was wrong $ ~/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>
$ export ANDROID_HOME=/path/to/sdk # or ANDROID_SDK_{HOME,ROOT}
$ 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:
> prepare-market
##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.
##Android manifest files
If you would like your AndroidManifest.xml file to automatically inherit
versionName and versionCode from your SBT project, add the
AndroidManifestGenerator
trait to your project. It will look for an
AndroidManifest.xml file, and add versionName and versionCode to that
template.
When you want to increase your version number, just use the standard SBT
increment-version
command.
##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.
##Building Java Android projects with sbt
If you don't use Scala yet and want to use the plugin to build your existing
Java app you can do so by adding the PlainJavaProject
trait to the project
definition:
class MainProject(info: ProjectInfo) extends AndroidProject(info)
with PlainJavaProject {
// usual project configuration
}
This will change the defaults to the directory structure expected by Android's
build.xml
file and skip the Proguard optimisation step.
In the sbt console run:
> sbt screenshot-emulator
or
> sbt screenshot-device
The screenshots will be written to emulator.png
/ device.png
in the project
root directory.
##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
. Don't hesitate to send a pull request!
##Mailing list
There's no official mailing list for the project but most contributors hang out in scala-on-android or simple-build-tool.
##Credits
This code is based on work by Walter Chang (saisiyat), turned into a plugin by Mark Harrah.