My favorites | Sign in
Logo
             
Search
for
Updated Sep 20, 2009 by hugo@josefson.org
Labels: Featured
GettingStarted  
Get started using Maven Android Plugin

Getting Started

Maven Repository

Setup your development environment

  1. Install Sun JDK 1.5+
  2. Install Android SDK 1.5_r2:
  3. http://developer.android.com/sdk/1.5_r2/
  4. Set environment variable ANDROID_SDK_15 to the path of your installed Android SDK.
  5. If you look in the pom.xml of the samples* project you will find the following dependency.
  <dependency>
    <groupId>android</groupId>
    <artifactId>android</artifactId>
    <version>1.5_r2</version>
    <scope>provided</scope>
  </dependency>
This corresponds to the android.jar file in the Android SDK which is needed to compile all Android applications. Install this file to your local repository with the following command.
mvn install:install-file -DgroupId=android -DartifactId=android -Dversion=1.5_r2 -Dpackaging=jar -Dfile=$ANDROID_SDK_15/platforms/android-1.5/android.jar

On Windows, that would be:

mvn install:install-file -DgroupId=android -DartifactId=android -Dversion=1.5_r2 -Dpackaging=jar -Dfile=%ANDROID_SDK_15%/platforms/android-1.5/android.jar

Optional: Test your development environment

If you want to test your environment, download and run the Samples*.

Create your own Android application (apk)

  1. Create a project using the android tool:
  2. Create a pom.xml in your project, using the sample apidemos-15/apidemos-15-app/pom.xml as template. (See Samples*.)
  3. Rename, and move the source directory to where Maven expects it:
  4.      mv src java
         mkdir -p src/main
         mv java src/main/
or if you don't want to change the directory structure, just add "sourceDirectory
    <build>
    ......
    <sourceDirectory>src</sourceDirectory> 
    </build>
to pom.xml.
  1. You won't need these files/directories with Maven Android Plugin, so you can remove them:
  2.      rm -r bin build.xml build.properties libs
    The default.properties file is currently not used by Maven Android Plugin, but will be, so leave that in place for now. default.properties and the gen folder are used by the ADT plugin in Eclipse, if you use that.

    (Also leave the "test" folder for now. You can later move it out to its own project. If you want, you can then look at the apidemos-15-instrumentationtest sample project.)
  3. To build your apk, simply:
  4.      mvn install
  5. To deploy your apk to the connected device:
  6.      mvn com.jayway.maven.plugins.android.generation2:maven-android-plugin:deploy

Do you think that last Maven command was long? It was. Check out TipsAndTricks.

Run instrumentation tests on device

Check out the apidemos-15-instrumentationtest project in Samples*.

You can create a project like that, by moving your "test" folder out and renaming it to for example "myproject-instrumentationtest". Then rearrange the folders within it like above, and use the pom.xml from apidemos-15-instrumentationtest as template.

More documentation

There is some more documentation on the Documentation page.

(*) Samples

Always use the version of samples linked from the Samples page, so that you get a usable version of its configuration.




Please feel free to update this page with more details / corrections! (Just ask hugo@josefson.org for edit permissions, and you will get it.)


Comment by dirk.dekok, Sep 20, 2009

hi there,

I had to set the version of the jayway maven-android-plugin to 2.1.0 instead of 2.1.1-snapshot, as configured in the just downloaded samples. In the maven repository I only found 2.1.0:

http://repo2.maven.org/maven2/com/jayway/maven/plugins/android/generation2/maven-android-plugin/

to be complete, new pom.xml: .. <plugin>

<groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>maven-android-plugin</artifactId> <version>2.1.0</version>
.. etc.

Comment by hugo@josefson.org, Sep 20, 2009

Hi Dirk,

Thank you for your comment!

I made a mistake in not specifying clearly that the "master" version of samples in git are not useful to an Android application developer, but the released version from the Samples page must be used instead.

I have now added an asterisk to all mentionings of the Samples on this page, and a footnote reminding that it is important to always use the linked version of samples from the Samples page.

An "Important note" is added to the Samples page. A full explanation is available on the Source page, where I believe most people might have been tricked into using a not-yet-released version of the samples.

Thanks, Hugo


Sign in to add a comment
Hosted by Google Code