Posted on by | Posted in Developer Blog, Mobile Blog, Tutorial | Tagged , , , ,

In my previous post, I showed you the basic setup for android with maven using the android-maven-plugin. Now I'll show you how to configure it to make releases with maven, and how to configure the plugins to save you some work.

Configuring the keystore data

If you have used the release archetype like in the previous post, most of the work is already done. The necessary plugins are configured and only need some additional data, like the data for your release keystore.

Looking into the poms, you'll find the property keys, you have to provide:

     ${sign.keystore}
     ${sign.alias}
     ${sign.storepass}
     ${sign.keypass}

Simply configure them into your maven settings.xml in the release profile (which is also configured in the parent pom):
(If you don't have a release key yet, check this out http://developer.android.com/tools/publishing/app-signing.html#cert)

   
       release
       
           /path/to/your/keystore/keystore.keystore
           your-key-alias
           your-keystore-password
           your-key-password
       
    

For our case, we removed everything related to proguard from the configs, beacuase we don't use it for this project. Instead of removing everything, you could also just disable it with the android-maven-plugin configuration

true

Adding scm connection and distribution management

Like you would normally, using maven releases, you have to add an scm connection to your parent pom, e.g.:

    
        scm:git:ssh://asd@some.git.server/my-android-project.git
        HEAD
    

If you have a server to deploy your maven artifacts to, now is the time to add it to your config (if you only build and deploy them from your local machine, you don't need this):

    
        
            releases-repository
            releases.some.address
            https://some.address/content/repositories/releases/
        
        
            snapshots-repository
            snapshots.some.address
            https://some.address/content/repositories/snapshots/
        
    

Configure the Android Manifest from Maven

To save us some nasty work, we also want to configure the Android manifest with our maven profiles (e.g. setting Debug to false for release, automatically update the version on releases, etc.)

For this, we'll need to filter the manifest in maven:
add following plugins to the parent pom:

                
                    org.apache.maven.plugins
                    maven-resources-plugin
                    2.6
                    
                        UTF-8
                    
                
                
                    org.codehaus.mojo
                    build-helper-maven-plugin
                    1.8
                

... and the config for them in the app module (and IT module) pom:

   
       
            
                ${project.basedir}/target/filtered-manifest
                true
                ${basedir}
                
                    AndroidManifest.xml
                
            
        
   ...
        
           ...
           
                org.codehaus.mojo
                build-helper-maven-plugin
                
                    
                        parse-version
                        
                            parse-version
                        
                    
                
            
            
                maven-resources-plugin
                
                    
                        initialize
                        
                            resources
                        
                    
                
            
           ...
        
    

Don't forget to update the Android manifest path in the android-maven-plugin to the filtered manifest location!

${project.build.directory}/filtered-manifest/AndroidManifest.xml

In the Android Manifest files of the modules, you can now insert the maven property placeholders for the versionCode and versionName


If you now build your project (clean install), the generated Android manifest should include the versionCode "100" and the version "1.0-Snapshot" (If you didn't change the version in the pom, yet).

Other than that, you have plenty of configuration possibilities of your AndroidManifest within the android-maven-plugin config, and with this setup you can easily alter the values for the different build profiles.

Building the release

To build the release, use

mvn release:prepare -Prelease

release:perform is not necessary here!

After the release is done, run

mvn release:clean

to clean up.

Note: you might want to let your scm ignore some files (e.g. release.properties and the target folders) so that you don't have to further clean up your directories after you run the release.

That's it, now you are able to build your android app releases with maven!

Here are the sources to check against: my-android-project sources

My next blog will be about Android & Continuous integration with Jenkins, so check our blog from time to time 🙂



2 Responses to Building Android projects with maven – part 2: Releases with maven


  1. HI Tobias,
    Nice explanation. I released my project http://www.embeddedunveiled.com/ on maven central. The group id is com.embeddedunveiled and artifact is scm. Please guide me which is the link that I should give to other developers so that they can integrate my artifact in their project.


  2. Pingback: Building Android projects with Maven – Part 1: Setup | synyx - Blog

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.