batch file - Executing cmd command using Maven -
i want execute command:
zipalign [-f] [-v] <alignment> infile.apk outfile.apk using maven. have execute command in android sdk/ tools directory. can me on how this? think can done using batch file not sure how create batch file. need command executed when type "mvn clean install". thanks
executing commands using maven
you can use maven exec plugin bound install phase.
in snippet below, commant ping argument 8.8.8.8 executed every time mvn install:
<project> ... <build> <plugins> <plugin> <artifactid>exec-maven-plugin</artifactid> <groupid>org.codehaus.mojo</groupid> <version>1.2.1</version> <executions> <execution> <id>my command runner</id> <phase>install</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>ping</executable> <arguments> <argument>8.8.8.8</argument> </arguments> </configuration> </execution> </executions> </plugin> </plugins> </build> ... </project>
, that's it.
update:
i see having trouble executing zipalign, not arbitrary command. that, there 2 ways.
using built-in zipalign of maven-android-plugin
as of release 2.5.0 of android maven plugin zipalign goal part of plugin. activate add goal zipalign execution (e.g. package phase) , set skip parameter in plugin configuration false:
<zipalign><skip>false</skip></zipalign> full <plugin> tag example:
<plugin> <groupid>com.jayway.maven.plugins.android.generation2</groupid> <artifactid>maven-android-plugin</artifactid> <inherited>true</inherited> <configuration> <sign> <debug>false</debug> </sign> <zipalign> <verbose>true</verbose> <inputapk>${project.build.directory}/${project.artifactid}.apk</inputapk> <outputapk>${project.build.directory}/${project.artifactid}-signed-aligned.apk </outputapk> </zipalign> </configuration> <executions> <execution> <id>alignapk</id> <phase>package</phase> <goals> <goal>zipalign</goal> </goals> </execution> </executions> </plugin> sources:
- here you'll find example using older version (still called
android-maven-plugin); - zipalignapkbuiltbymaven: describes how automatically zipalign apk has been built maven.
- simpligility: maven android plugin zipalign , improved verification
- another example: a full
pom.xmluseszipalign.
zipalign using exec-maven plugin
the code below bind functionality of zip aligning package phase, overwriting previous zip aligned file without asking.
<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>package</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> please note profile has added pom actual apk. can't add parent pom. reason uses maven property defines artefact name (project.build.finalname).
Comments
Post a Comment