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.
- Eclipse Indigo or Juno
- Android Developer Tools 0.9.9+
- 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:instrument->run instrumantation tests
- android:pull->copy file from device
- android:push->copy file to device
Some useful links are
Murat Aydın maydin [at] gmail dot com