Nov
1
2012

Step by Step Android Development with Maven

Maven is a great build tool and in this tutorial, i will show how to integrate Maven with Android.

Requirements:

  1. Eclipse Indigo or Juno
  2. Android Developer Tools 0.9.9+
  3. Java JDK

Install Java JDK and point it in the eclipse as shown below:

If you have Eclipse Classic, then you need to download and install Marketplace Client to Eclipse using the menu link Install new Software → Switch to the Indigo Repository → General Purpose Tools → Marketplace Client.

Then click Help->Eclipse Marketplace and search “android m2” and install “Android Configurator for M2E”.

Check all everything as shown below and click next.

Accept the licence agreement and install.

Now we will create an Android Project using Maven. Click File->New->Project. Then choose Maven Project as shown below and click next:

Click next again in the next screen and click Add Archetype in the screen below:

Archetype is a Maven project templating toolkit and we will add an archetype for Android.

Fill the fields as shown below and click OK:

Choose “de.akquinet.android.archetypes” in the list and click next:

Fill the screen fields as shown below and click finish:

Platform is the Android version. Android-plugin-version is the latest version of androin-maven-plugin.

And the Android Project that have Maven support is created. If there is a compiler error about src/test/java, create that folder manually. The resulting folder structure is shown below:

Then update the Maven Project as shown below:

Add the android sdk path and Android emulator name to the pom.xml which is under the AndroidManifest.xml as shown below:

Emulator name will be used for starting emulator and deploying and running the Android application.

Right click and choose Run As->Maven Install as shown below:

This will produce the apk of the Android App as shown below. Refresh if you cant see the apk file.

Now we will start an emulator using Maven. Right click the Android Project and choose Run As->Maven Build…

Enter android:emulator-start to Goals and press Run as shown below:

Android emulator defined in the pom.xml will start.

Now we will deploy the apk to emulator. Right click the Android Project and choose Run As->Maven Build…

Enter android:deploy to Goals and press Run as shown below:

Now we will run the app in the emulator. Right click the Android Project and choose Run As->Maven Build…

Enter android:run to Goals and press Run as shown below:

Some available Goals are:

  • android:deploy
  • android:undeploy
  • android:redeploy
  • android:instrument->run instrumantation tests
  • android:pull->copy file from device
  • android:push->copy file to device
  • android:run
  • android:emulator-start
  • android:emulator-stop
  • android:emulator-stop-all
  • android:apk
  • android:deploy-dependencies
  • android:dex
  • android:generate-sources
  • android:internal-integration-test
  • android:internal-pre-integration-test

Some useful links are

Murat Aydın maydin [at] gmail dot com

About the Author: Murat Aydın

Murat Aydin is a senior software engineer in a company that develops software technologies for defense systems, and is an enthusiastic Android developer. He has several Android applications in Google Play. He is a Sun Certified Java Developer and has eight years of experience in developing web based applications using Java technologies, and desktop and engineering applications using .Net technologies. Murat Aydin earned his BSc degree in Computer Engineering from METU (Middle East Technical University) and his MSc degree in Software Engineering from METU. He is a member of GDG Ankara (Google Developer Group Ankara, www.gdgankara.org), who organize several Android events in GDG Ankara, such as Android Developer Days. (www.androiddeveloperdays.com)

3 Comments + Add Comment

Leave a comment

Partners