Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle produces unsigned release apk

Tags:

android

gradle

I have a project with following structure:

Root
    \__main_project
    |
    \__modules
       \__
       |  library1
       |   
       \__
          library2

I have following config in my gradle:

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
    }

    signingConfigs {
        release {
            storeFile file('/home/home/.signing/test.keystore')
            storePassword 'testtest'
            keyAlias 'testtest'
            keyPassword 'testtest'
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

to build my project I run following command:

./gradlew :main_project:assembleRelease

but it only produces main_project-release-unsigned.apk

So my question why it produces unsigned apk when I specified all required configuration. Thank you.

like image 549
endryha Avatar asked Dec 25 '22 12:12

endryha


2 Answers

The "official" way to configure the build.gradle file as recommended by Google is explained here.

Basically, you add a "signinConfig", in where you specify the location an password of the keystore. Then, in the release build type, refer to that signing configuration.

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            storeFile file("myreleasekey.keystore")
            storePassword "password"
            keyAlias "MyReleaseKey"
            keyPassword "password"
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

Then build the app with the "assembleRelease" task.

like image 93
GaRRaPeTa Avatar answered Dec 31 '22 11:12

GaRRaPeTa


Try ./gradlew assembleRelease.

Also you'll probably want to augment the buildTypes release section

buildTypes {
    release {
        runProguard true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.release
        zipAlign true
    }
}

Also see task askForPasswords on How to create a release signed apk file using Gradle? for how to prompt for the passwords so they aren't stored in this file.

like image 27
Jerry101 Avatar answered Dec 31 '22 12:12

Jerry101