Skip to content

A simple flashlight android app written in clojure, based on the example at https://github.com/jayway/maven-android-plugin-samples. Meant to demonstrate a full toolchain for android development in clojure. The example is also simple enough to serve as a skeleton for others to base their clojure/android projects on

Notifications You must be signed in to change notification settings

hsaliak/android-clojure-flashlight-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flashlight Example for Clojure based on  the example found at https://github.com/jayway/maven-android-plugin-samples

Goals
====
1)Android development in Clojure
2)No java bridge. 
3)Ability to leverage Android tools and workflow. Ie: using generated resources.
4)A REPL with Android libraries available for rapid prototyping
5)Able to use DDMS on the app. With stack traces hitting clojure line numbers.
6)Escape getting mugged out of all your RAM by gangster IDEs 
7)Use ProGuard to shrink the apk size. - Done , a size reduction of around 300k can be achieved by pruning unused parts of clojure core. apk size is around 900k.
8) TODO: Optimize with proguard

The purpose of this codebase is to serve as an illustrative example of how to achieve the above goals. The idea is that the code will allow you to replicate this set-up for your android projects, giving you a productive environment quickly. 

Prerequisites:
====
Android SDK:
- http://developer.android.com/sdk/index.html
It is assumed that you have the SDK and a (Froyo) AVD ready.
Maven:
The whole build is managed by maven. 
- http://maven.apache.org 
You need to have a fair understanding of maven to not be put off by the xml work that needs to be done.

Maven Android Plugin: 
The example implemented here is the flashlight example that demonstrates the android-maven plugin. The code for the Java version of this can be found at:
- https://github.com/jayway/maven-android-plugin-samples
To understand the maven-android example, this may be a good place to start.
There is a detailed discussion of this plugin as well as all of maven here: 
- http://www.sonatype.com/books/mvnref-book/reference/public-book.html
- http://www.sonatype.com/books/mvnref-book/reference/android-dev.html

Clojure maven Plugin:
The clojure-maven plugin is also required, and it can be found here:
- https://github.com/talios/clojure-maven-plugin

The project was first created by using the 'android' command found in the android SDK. 
#android create project -t android-8 -p helloflashlight -k com.yourname -a HelloFlashlight
Refer to the android documentation for further details.

Add maven support to this project, this is done by creating a pom.xml with the appropriate details.
See http://www.sonatype.com/books/mvnref-book/reference/android-dev-sect-using.html

Add clojure support to the project. For this, you will need to add the official clojure maven repository (for clojure-contrib) and the clojars repository for swank.  (Goal 4)

Add proguard support to the project. See http://proguard.sourceforge.net/ The tool is quite complex, so a lot of researching on the internet may be required. 
Clojure is also fairly complex and needs special treatment when used with proguard. The current approach and its limitations are explained in proguard.cfg

Reading the material linked above, and this project's  pom.xml should make the workflow clear.
====

Reccomended reading order:
1)pom.xml.
2) com/hsaliak/HelloFlashlight.clj ( I know I am missing 1 package level)
3) res/layout/main.xml
4) res/values/strings.xml
5) proguard.cfg 
6) You may want to peek into clojure-inits.txt at the top level as a reference.


Debugging:
You will be able to run DDMS from your android SDK. This can be used to debug the app once its deployed in the emulator.

REPL:
pom.xml contains the swank plugin.
Running "mvn clojure:swank" will start a swank server. Emacs can be used to  slime-connect it. 
In the REPL, Android libs will be available to test. 
Eg:
user> (import [android.graphics Color])
android.graphics.Color
user> Color/WHITE
-1
user> Color/RED
-65536


Compilation:
#mvn install android:deploy
This step requires the avd to be started using the 'android' tool. 
pom.xml can be set up to start the emulator with the android:start-emulator target
but has not yet been set up to do so.

Useful targets:
android:generate-sources  - THis will create R.java, useful to know how to look at when coding the clojure bits
android:undeploy : Make sure you enable undeploy before deploy so that you will always be running the latest app on your emulator
android:deploy



Startup time 
==========
The app took 9 seconds to start up on a froyo emulator. [ Measured via ddms] 
02-03 14:34:11.560: INFO/ActivityManager(59): Displayed activity com.hsaliak/.HelloFlashlight: 8767 ms (total 8767 ms)

The app took 2 seconds to start up on a Samsung Galaxy S I9000 [Measured via ddms ]
02-03 14:03:08.969: INFO/ActivityManager(2494): Displayed activity com.hsaliak/.HelloFlashlight: 2163 ms (total 2163 ms)

About

A simple flashlight android app written in clojure, based on the example at https://github.com/jayway/maven-android-plugin-samples. Meant to demonstrate a full toolchain for android development in clojure. The example is also simple enough to serve as a skeleton for others to base their clojure/android projects on

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published