Aryeh Katz
Aryeh Katz

Reputation: 50

Gradle - Different configs for release and debug don't work

I'm trying to set up Gradle to have different settings for release and debug builds.

Use case: developers do not need the signing file and configs to build a debug version.

But gradle refuses to sync/build a debug version because a file is missing (def keystorePropertiesFile = rootProject.file("keystore.properties") - but those settings are for release build only.

What am I doing wrong?

...

android {

    ...
    defaultConfig {
        ...
    }
    buildTypes {
        release {
            ...
            signingConfigs {

                def keystorePropertiesFile = rootProject.file("keystore.properties")

                // Initialize a new Properties() object called keystoreProperties.
                def keystoreProperties = new Properties()

                // Load your keystore.properties file into the keystoreProperties object.
                keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']

            }
        }
        debug {
            ...
        }
    }
    ...
}
...

Upvotes: 0

Views: 539

Answers (2)

AlexGera
AlexGera

Reputation: 783

You can always out some checking in plain Java like :

File keystorePropertiesFile = new File(distrDir, fileName)
  if (!keystorePropertiesFile.exists()) {
     println "DEBUG message, properties set not from production file"
     // throw new GradleException('Also you can interrupt everything')
  } else {
     println "Do your file loading here..."
 }

Upvotes: 1

Umar Hussain
Umar Hussain

Reputation: 3527

whole gradle file is evaluated when building. so it will throw error. Incase of debug I think gradle auto sign the apk with the android debug keystore

Either comment the signing for release

or

provide a properties file with dummy content so that gradle build works incase of debug

Upvotes: 1

Related Questions