2
votes

I've tried to look for similar questions, but no luck.

I'm building my Gradle project from the command line, and supply the passwords in the gradle release command line using -P.

Here's my build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
    }
}

apply plugin: 'android'

android {
    signingConfigs {
        release {
             storeFile file("C:/Android/Dev/keystore/dm.keystore")
             keyAlias KEY_ALIAS
             storePassword STORE_PASSWORD
             keyPassword KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

    compileSdkVersion 'android-13'
    buildToolsVersion '22.0.1'

    buildTypes {
        release {
            minifyEnabled false
            proguardFile getDefaultProguardFile('proguard-android.txt')
        }
    }
}

When I try to do a clean, it gives me:

Could not find property 'KEY_ALIAS' on SigningConfig_Decorated{name=release, storeFile=C:\Android\dev\keystore\dm.keystore, storePassword=null, keyAlias=null, keyPassword=null, storeType=C:\Android\dev\keystore\dm.keystore}.

Someone said that the 'signingConfigs' should come before the 'buildTypes', and it does.

Is there any way that I can keep the 'signingConfigs' in there, but maybe modified somehow, and not have it complain?

If I take 'signingConfigs' out, and add it before I do the release it works.

Thanks!

1
You need to use gradle <build cmd> -PKEY_ALIAS=<alias>. And do it for all the variables. I would highly suggest to put those in a gradle.properties file.Jared Burrows
I do that when I do a release, but I shouldn't have to do it when I do a clean, you'd think. Isn't there any way to keep 'signingConfigs' in there without it giving an error? I don't want to go the route of using a .properties file since there isn't a default .properties file when I create the project except for local.properties.user1572522
Thanks for the edit. Okay, I think it's dumb that it would complain about not having the parameters for 'clean' or 'assembleDebug' even if 'signingConfigs' is in there, so I just have to deal with it.. Thanksuser1572522

1 Answers

4
votes

try this

 def key="default"
def storePass="default"
def keyPass="default"

if (project.hasProperty("KEY_ALIAS")) {
    key = KEY_ALIAS
}
if (project.hasProperty("STORE_PASSWORD")) {
    storePass = STORE_PASSWORD
}
if (project.hasProperty("KEY_PASSWORD")) {
    keyPass = KEY_PASSWORD
}


signingConfigs {
    release {
        storeFile file("C:/Android/Dev/keystore/dm.keystore")
        keyAlias key
        storePassword storePass
        keyPassword keyPass
    }
}

i also recommend you to store your signing information in separate file