public void execute ( ) throws MojoExecutionException , MojoFailureException { // If we're not on a supported packaging with just skip (Issue 87) // http://code.google.com/p/maven-android-plugin/issues/detail?id=87 if ( ! SUPPORTED_PACKAGING_TYPES . contains ( project . getPackaging ( ) ) ) { getLog ( ) . info ( "Skipping zipalign on " + project . getPackaging ( ) ) ; return ; } ConfigHandler configHandler = new ConfigHandler ( this , this . session , this . execution ) ; configHandler . parseConfiguration ( ) ; parsedInputApk = FilenameUtils . separatorsToSystem ( parsedInputApk ) ; parsedOutputApk = FilenameUtils . separatorsToSystem ( parsedOutputApk ) ; getLog ( ) . debug ( "skip:" + parsedSkip ) ; getLog ( ) . debug ( "verbose:" + parsedVerbose ) ; getLog ( ) . debug ( "inputApk:" + parsedInputApk ) ; getLog ( ) . debug ( "outputApk:" + parsedOutputApk ) ; getLog ( ) . debug ( "classifier:" + parsedClassifier ) ; if ( parsedSkip ) { getLog ( ) . info ( "Skipping zipalign" ) ; } else { boolean outputToSameFile = sameOutputAsInput ( ) ; CommandExecutor executor = CommandExecutor . Factory . createDefaultCommmandExecutor ( ) ; executor . setLogger ( this . getLog ( ) ) ; String command = getAndroidSdk ( ) . getZipalignPath ( ) ; List < String > parameters = new ArrayList < String > ( ) ; if ( parsedVerbose ) { parameters . add ( "-v" ) ; } parameters . add ( "-f" ) ; // force overwriting existing output file parameters . add ( "4" ) ; // byte alignment has to be 4! parameters . add ( parsedInputApk ) ; String outputApk = outputToSameFile ? getTemporaryOutputApkFilename ( ) : parsedOutputApk ; parameters . add ( outputApk ) ; try { getLog ( ) . info ( "Running command: " + command ) ; getLog ( ) . info ( "with parameters: " + parameters ) ; executor . setCaptureStdOut ( true ) ; executor . executeCommand ( command , parameters ) ; if ( FileUtils . fileExists ( outputApk ) ) { if ( outputToSameFile ) { // No needs to attach zipaligned apk to artifacts try { FileUtils . rename ( new File ( outputApk ) , new File ( parsedInputApk ) ) ; } catch ( IOException e ) { getLog ( ) . error ( "Failed to replace original apk with aligned " + getFullPathWithName ( outputApk ) , e ) ; } } else { // Attach the resulting artifact (Issue 88) // http://code.google.com/p/maven-android-plugin/issues/detail?id=88 projectHelper . attachArtifact ( project , APK , parsedClassifier , new File ( outputApk ) ) ; getLog ( ) . info ( "Attach " + getFullPathWithName ( outputApk ) + " as '" + parsedClassifier + "' to the project" ) ; } } else { getLog ( ) . error ( "Cannot attach " + getFullPathWithName ( outputApk ) + " to the project" + " - The file does not exist" ) ; } } catch ( ExecutionException e ) { throw new MojoExecutionException ( "" , e ) ; } } }
Execute the mojo by parsing the confign and actually doing the zipalign .