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

4

2 回答 2

7

根据这个论坛:https ://code.google.com/p/android/issues/detail?id=212591

“嗨,我们不再生成未对齐的 apk。作为加快速度的改进的一部分,我们生成了已经对齐的 apk。因此,您只需获得最后一个,而不是两个。

@yair.kikielka 谢谢。”

于 2016-09-21T09:17:56.473 回答
4

回复编辑(20160922):

那么输出文件真的对齐了吗?

是的 !您可以使用验证

zipalign -c -v 4 路径/文件名

当您对 gradle version >=2.2 生成的 apk 文件运行此命令时,您将得到 "Verification succesful" 。这意味着已经对齐。

于 2016-10-12T16:45:27.137 回答