androidgradleandroid-gradle-pluginzipalign

Gradle task to execute android zipalign


I would like to build a gradle Exec task that would run android's zipalign on my signed apk file, and then validates the the alignment.


Solution

  • Variables:

    zipalign task:

    task zipAlign(type: Exec) {
    
            executable "${ANDROID_HOME}${ZIPALIGN_PATH}"
            args "-f",  "-v", "4", "${buildDir}${OUTPUT_APK_PATH}${APK_FILE_TO_ALIGN}", "${buildDir}${OUTPUT_APK_PATH}${APK_FILE_NAME}"
    
    }
    

    zipalign verification task (note that this task depends on the zipalign task):

    task verifyZipAlign(type: Exec, dependsOn: 'zipAlign') {
    
            executable "${ANDROID_HOME}${ZIPALIGN_PATH}"
            args "-c",  "-v", "4", "${buildDir}${OUTPUT_APK_PATH}${APK_FILE_NAME}"
    
    }