My favorites | Sign in
Project Home Wiki Issues Source
Search
for
ZipalignAPKBuiltByMAven  
Describes how to automatically zipalign an APK that has been built by Maven.
Updated Sep 30, 2011 by h...@josefson.org

Introduction

Before shipping an APK it should be zip aligned. This is a procedure that aligns the application archive so that it is optimised for the Android phone. This article shows how to add this function as a profile in the pom of an Android Maven project.

Details

As of release 2.5.0 of the Android Maven Plugin the zipalign goal is part of the plugin. To activate simply add the goal zipalign as an execution e.g. to the package phase. More details are at the simpligility web site.



















Old Details using the exec plugin

To add the functionality for zip aligning to your build use the code below. Please note that this profile has to be added to the pom for the actual APK. You can't add it to a parent pom. The reason for this is that it uses the Maven property that defines the artefact name (project.build.finalName).

  <profiles>
        <profile>
            <id>sign</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1.1</version>
                        <executions>
                            <execution>
                                <id>zipalign</id>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <phase>install</phase>
                                <configuration>
                                    <executable>${ANDROID_HOME}/tools/zipalign</executable>
                                     <arguments>
                                        <argument>-f</argument>
                                        <argument>4</argument>
                                        <argument>target/${project.build.finalName}.apk</argument>
                                        <argument>target/${project.build.finalName}-zipped.apk</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

This will bind execution of zipalign to the package phase, just after the apk signing, when running install with the sign profile. It will overwrite previous zip aligned file without asking.

For more information on zip aligning and the zipalign tool see Androids official documentation.


Sign in to add a comment
Powered by Google Project Hosting