Android Studio 2.2 update: aligned APK (zipAlign) not generated using the new Gradle Plugin 2.2.0
Asked Answered
C

2

11

After updating Android Studio to version 2.2 I also got an update for the Gradle Plugin (it was 2.1.3):

...
classpath 'com.android.tools.build:gradle:2.2.0'
...

I see the unaligned variant APK file but other variants are not generated anymore. I tryed to enable the zip align:

buildTypes {
        release {
            minifyEnabled false
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            applicationIdSuffix '.debug'
        }
}  

but nothing changes. Any ideas?

I "solved" turning back to

classpath 'com.android.tools.build:gradle:2.1.3'

in the project level build.gradle.

EDIT (20160922):

Thanks to Fayder Florez for his response. It's correct, the build environment now produce only one apk (https://code.google.com/p/android/issues/detail?id=212591).

But using by code (that rename de output file name using VERSION CODE and VERSION NAME):

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def padVersionCode = variant.versionCode.toString();
        padVersionCode = padVersionCode.padLeft(5, '0')
        def newApkName = "${output.baseName}_${padVersionCode}-${variant.versionName}"

        if (!output.zipAlign)
            newApkName = newApkName + "_unaligned"

        newApkName = newApkName + ".apk"
        output.outputFile = new File(output.outputFile.parent, newApkName)
    }
}

I get the "_unaligned" appended to the output file name, so I suppose that output.zipAlign is false.

So is the output file really aligned?

EDIT (20161013)

Thanks to ending0421 and it's suggestion to check the apk using the build tool:

zipalign -c -v 4 path/fileName

Now I now that the APK is generated correctly and the zipalign command syays:

Verification succesful

Chimaera answered 20/9, 2016 at 10:6 Comment(1)
I verified that output.zipalign is always null and hence the if condition gets satisfied and the produced apk name contains suffix "_unaligned.apk" (as per code in OP). However the resultant file is zipaligned.Desinence
L
7

According to this forum: https://code.google.com/p/android/issues/detail?id=212591

"Hi, we don't generate unaligned apks any more. As part of the improvements to speed things, we generate the apk already aligned. So, instead of two, you just get the final one.

@yair.kikielka Thanks."

Lacerate answered 21/9, 2016 at 9:17 Comment(0)
M
4

Reply EDIT (20160922):

So is the output file really aligned?

Yes ! You can verify using

zipalign -c -v 4 path/fileName

When you run this command on apk files which generated by gradle version >=2.2 , you will get "Verification succesful" . That means already aligned .

Mesozoic answered 12/10, 2016 at 16:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.