Gradle zipAlign task not working?

It appears the Gradle zipAlign task isn't working for me, not sure what I'm doing wrong. I've tried including the zipAlign task, and not including it, but it doesn't seem to make a difference. My gradle scripts spit out a "release" build, but it's never zipAligned according to the developer console when I try to upload my .apk.

Here's my build script:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4.2'
    }
}

apply plugin: 'android'

dependencies {
    compile project(':facebook-android-sdk-3.0.1:facebook')
    compile project(':google-play-services_lib')
    compile project(':nineoldandroids')
    compile project(':SlidingMenu-master:library')
    compile project(':ViewPagerIndicator')
    compile project(':volley')
    compile project(':windowed-seek-bar')
    compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}

android {
    buildToolsVersion "17.0"
    compileSdkVersion 17

    signingConfigs {
        debug {
            storeFile file('keystores/debug.keystore')
        }
    }

    buildTypes {
        debug {
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }

        release {
            zipAlign true
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }
    }
}

Any help appreciated!

Answers


Your release build type is not configured for signing.

If you are signing your apk manually, you need to run ZipAlign manually as well. ZipAlign must happen after signing.

Gradle will zipalign an apk only if it can sign as well.

To setup signing for the release config, you'll need to first create a new signing config, then assign it to the build type.

android {
  signingConfigs {
    release {
      storeFile file("/path/to/keystore")
      storePassword "??"
      keyAlias "??"
      keyPassword "??"
    }
  }

  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }
}

Note that all 4 parameters in the signing config are required, otherwise it'll consider some values are missing and it won't even attempt to sign.


It is possible to take any existing Android Studio gradle project and build/sign it from the command line without editing any files. This makes it very nice for storing your project in version control while keeping your keys and passwords separate and not in your build.gradle file:

./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD

Need Your Help

Why force unwrapping is required in case of enum and switch?

ios swift enums

I have notice weird swift behaviour, because in my opinion colours variable shouldn't be force unwrapped in case of switch written below, but without unwrapping compiler shows me an error message.

Check if a string variable has an integer value

vb.net string visual-studio-2010 parsing integer

I am working on a project which allows kids to send a message to Santa. Unfortunately, if they enter a string instead of an integer in the AGE field, the program crashes and returns Conversion from