简体   繁体   中英

Gradle produces unsigned release apk

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM