Building Android Project with Maven and Eclipse


Android, Maven and Eclipse, it appears to be best combination, and yes it is, but to set it up is a very time consuming task.  

Most of the time searching on Google or duckduckgo is a panacea for all technological problems or blocks.  However I found no resource is complete and takes long to figure out that, also most of them out-dated.

Anyway here is the checklist, I am not putting any links here as its easy to find out how to fulfil each checkpoint.  My try is to make it version agnostic.


Installations required


Java
Maven
Android sdk
Eclipse

System Configuration (Win64)


1. Set up home variables for Java, Maven, Android
2. Set up path for Java, android_home/tools, M2_HOME/bin

Eclipse JVM settings


1. JRE settings - JAVA_HOME/jre
2. Maven settings - i preferred to have external maven
3. Android setup home
4. Eclipse plugins
- m2e
- android
- m2e-eclipse-android-plugin


Maven Configurations


1. Download maven archetype catalog xml as central-archetype-catalog.xml on to .m2 directory [ in same directory where your settings.xml reside]
http://repo1.maven.org/maven2/archetype-catalog.xml
2. Install for android SDK Manager, install all extras for step3 mvn install to work
3. download and mvn install Maven Android SDK Deployer
4. install appropriate to your sdk version with -P option


Create a Maven Project from Archetypes

1. Create a folder for project using windows explorer
2. Eclipse Menu
file >> new Maven Project >>
3. uncheck default location and browse the one created in step 1
4. Create Catalog -> local Archetype catalog -> select catalog xml created in Maven conf step1.
5. back in New Maven Project window, select newly created catalog, type filter android
6. select android-quickstart, and next
7. type groupid(your pkg name) and artifactid (your project name) and finish
8. Archetype will create sample project, with sample pom.xml, which needs a change
If all is well, eclipse will show 1 compile-time error for R.java, that's fine. Keep going
Before continuing complete pom and settings file changes and then run mvn clean install, this should build successfully.


Further settings.xml and pom.xml settings


POM Changes
1. add dependency and adjust version number appropriately

<dependencies>

<dependency>

<groupId>android</groupId>

<artifactId>android</artifactId>

 <version>4.0.3_r3</version>

  <scope>provided</scope>

</dependency>

</dependencies>



2. also adjust SDK version number appropriately in plugin

<configuration>

<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>

<assetsDirectory>${project.basedir}/assets</assetsDirectory>

<resourceDirectory>${project.basedir}/res</resourceDirectory>

<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>

<sdk>

<platform>15</platform> 



3. Last add these 3 sections to settings.xml

<pluginGroup>

com.jayway.maven.plugins.android.generation2</pluginGroup>

</pluginGroups>



<profile>

<id>android</id>

<properties>

<android.sdk.path>C:\Androiddev\android-sdk</android.sdk.path>

</properties>

</profile>




<activeProfiles> 

<activeProfile>android</activeProfile>

</activeProfiles>



If you think something is missing or required, pl drop a line.

JS

Hg Mercurial Vs Git

After much deliberation for sometime, finally I have decided to stick to Hg Mercurial.

Primarily my requirements were
- keep tags and/or branches and you can clone it to specific revision [ which is similar to rebasing to recommended  baseline in ClearCase]
- it should be easy to use and maintain i.e commands should be simple to use
- I need it for personal code library for template projects.

Overall I found mercurial is apt for my need.  In my personal opinion, Git has bit of learning curve than Hg Mercurial.  So right now sticking to must have option rather nice to have one.


Simplistic view of Spring

What is Spring?

TO bare minimum Spring is
Lightweight - Non-intrusive to your applications
Dependency Injection
Aspect-Oriented
Container - configuration and Management of lifecycle of Application objects
Framework - compose complex applications from simple components

What are spring modules? and why its there?

On top of these 6features, spring provides ready made modules to easy development. Otherwise if this is not something you are after you can plug-in/configure your own modules. Also Spring provides integration points to plugin other modules e.g. Hibernate

 Spring framework is made up of six modules
  1. Core Spring cotainer
  2. DataAccess & integration
  3. AOP
  4. Testing
  5. Web and Remoting
  6. Instrumentation

(Image take from Spring in Action Ed 3MEAP, first chapter available on Manning website)

What is Spring Core?

- Spring Core is made up of BeanFactory and ApplicationContext

- BeanFactory provides configures and manages bean instances using DI

- Application Context provides a way to configure Spring.

- Spring supports several implementations,

What is Data Access and Integration?

Spring doesnt have any ORM on its own, it just has Spring JDBC (core class JDBCTemplate)
It provides integration points with tools like Hibernate

What is web and remoting module?

Spring provides Spring MVC and Spring Portlet for web

Also supports Struts like frameworks...

Remoting has support for RMI and JAX-WS (contract first approach)

Jax-ws and Jboss


Jboss supports JAX-WS in 3 flavours.

# native - which is jboss proprietary implementation for jax-ws. It comes default with jboss5.0.0GA.

# apache CXF - this supports Jax-ws implementation which apache provides. This isnt Axis, Axis is something parallel to JAX-WS itself.

# metro stack - Jboss supports this as well, its a dedicated Metro only implementation. You get separate download for it, change JBOSS-HOME and other properties. Run a build script, and thats it. It adds stuff in Jboss directory and ready for work.

Thats it for now, its friday afternoon
Jai Ho

REST is not rest.


REST Services RS is just another way of representing web services, and its not just rest other than SOAP-WS.

What is it?
Its a full fledged service no less than any other computational system or to that matter its sister SOAP-WS. RS represnts a state of some resource at service side and upon request it changes the state and transfers that state to client, but resource remains.

So whats resource?
It can be anything and evrything you think of in the business context, e.g. You access Sydney's weather on weatherzone.com.au or it may be list from yahoo shoping.

Whats request? And how can i change state of the resource on service side?
A request should have 2 parts; HTTP method / VERB and actual parameters that can be a query string or a raw XML.
# if you want list it 'll be GET and query string with ? Followed by name-val pair.
# if want to change/add something POST and raw XML in HTTP request
Likewise there can be PUT for update, DELETE for delete function.

And response?
- Response is raw xml

What is JAX-RS?
- its java api for RS, nothing greek here. To implement few things are diff
# @WebServiceProvider
# @BindingType - HTTP
# @ServiceMode for just payload or whole message.
# Also to send and receive xml, you can use XmlEncode and XmlDecode.
# one more caution about exceptional handling it emits Http status code.

more on RS later...Till then..

Jai Ho

Refactoring code - big deal !

what is it really?
Just to simplify code so that its easy to understand and maintain.

But why its required any way?
I think, i am writing code which is easy to maintain and understand. So is it a myth? Ans is NO...
you write a code as per well designed abstractions and objects, but change to existing code makes software design to decay. Once that starts happening, you need to start to refactor code in small bursts. that way you will save code, design and most importantly time of any coder who will work on it.

Whats most visible difference that makes?
You would become more efficient developer as you would do things quickly over period of time and Your code will be less buggy. But that sounds counterproductive, since you have to devote time to refactor other than dev time. Yes, All good things take sometime to work, so it is.

When should i do it?
when i am
# add/changing new method
# fixing a defect
# dont understand some code

Are there any troubles?
# watch while changing interfaces methods, if its public or published its not easy to refactor
# watch for thrown exceptions

how can i quickly locate places in code that needs refactoring?
Those pointers will be in next post...

Until then...Jai ho..

Design pearls

Head first design pattern is a must must READ. Some of the principles are
# Encapsulate that varies.
# Every class has single responsibility to change.
# Keep interacting objects loosely coupled.
# Favour composition over inheritance. If required, inheritance should be used for type hierarchy and not behaviour.
# Use abstractions instead of concrete classes.
# Classes should be open for extension and closed for modification. This minimizes any changes to existing code / class hierarchy and new classes designed for changes. Decorator Pattern uses this principle, for example famous java IO API's.
More principles next time. Until then...
Jai ho.