Android – Gradle, ‘could not find property’

androidgradle

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!

Best Answer

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

Related Topic