Running zipalign with zopfli recompression after creating the APK from the command line to reduce it

As mentioned in the Google Developers article , you can now recompile the APK files using zopfli by running zipalign -z. In my case, a decrease of 200 KB is observed in the 5.1 MB APK file.

I usually create an APK using a special shell script by running gradle assembleRelease.

I want to run zipalign -z <the final apk>after the above command. However, it zipalignis in a directory build-tools/<build tools version>that I can not find, except to extract <build tools version>from the file build.gradleand construct the path manually.

Is it possible to start zipalignusing a command gradlethat automatically starts zipalignin the correct directory build-toolswithout having to restore the path?

For example, a command such as gradle runBuildTools zipalign -z $FINAL_APK $FINAL_APK.out

+4
source share
1 answer

The article you linked to has been updated using the gradle task to add zopfli compression to the end of the assembleRelease task.

//add zopfli to variants with release build type
android.applicationVariants.all { variant ->
  if (variant.buildType.name == 'release') {
    variant.outputs.each { output ->
        output.assemble.doLast {
            println "Zopflifying... it might take a while"
            exec {
                commandLine output.zipAlign.zipAlignExe,'-f','-z', '4', output.outputFile.absolutePath , output.outputFile.absolutePath.replaceAll('\\.apk$', '-zopfli.apk')
            }
        }
    }
  }
}
+2
source

Source: https://habr.com/ru/post/1630004/


All Articles