Search code examples
androidandroid-studiozipalign

How to zipalign apk file on windows 8.1


Yes i searched google and other questions

I don't see any zipalign etc in my sdk tools directory

Using latest android studio on windows 8.1 64 bit

I also tried build gradle but it also does nothing at output apk file

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.monstermmorpg.pokemon"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}

So how do i zipalign my output apk to publish at google store

Here screenshot

enter image description here


Solution

  • You should zip align and sign your APK with Android Studio.

    With this corrected build.gradle you will be able to run gradlew assembleRelease.

    Generate your keystore with Android Studio like this:

    http://developer.android.com/tools/publishing/app-signing.html#studio

    Your build.gradle should look like this:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "21.0.0"
    
        defaultConfig {
            applicationId "com.monstermmorpg.pokemon"
            minSdkVersion 9
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
    
        signingConfigs { // <-- Signing Config you needed 
            release {
                storeFile file("other.keystore")
                storePassword "android"
                keyAlias "androiddebugkey"
                keyPassword "android"
            }
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.release // <-- applied signing config
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.0.0'
    }
    

    Read more here: http://tools.android.com/tech-docs/new-build-system and http://developer.android.com/tools/publishing/app-signing.html