Android Gradle: signingConfig.name must not be null

Viewed 905

After updating Gradle Wrapper to 5.6.4 and Gradle Plugin to 3.6.0, I get the following error:

Caused by: java.lang.IllegalStateException: signingConfig.name must not be null

My configuration looks like this:

root:

ext {
    Properties localProps = new Properties()
    localProps.load(rootProject.file('local.properties').newDataInputStream())

    mySigningConfigs = [
            debug  : SigningConfig.newInstance([
                    keyAlias     : "${localProps['keyAlias']}",
                    keyPassword  : "${localProps['keyPassword']}",
                    storeFile    : file('carrierKeystore.jks'),
                    storePassword: "${localProps['storePassword']}"
            ]),
            release: SigningConfig.newInstance([
                    keyAlias     : "${localProps['keyAlias']}",
                    keyPassword  : "${localProps['keyPassword']}",
                    storeFile    : file('carrierKeystore.jks'),
                    storePassword: "${localProps['storePassword']}"
            ])
    ]
}

module:

buildTypes {
        debug {
            signingConfig mySigningConfigs.debug
        }
        release {
            signingConfig mySigningConfigs.release
        }
    }

It worked great before, but not it's always saying name is null. Do you have any idea? Thanks.

3 Answers

I figured out the problem

move the lines

buildTypes {
        debug {
            signingConfig mySigningConfigs.debug
        }
        release {
            signingConfig mySigningConfigs.release
        }
    }

to

signingConfigs {
        debug {
            mySigningConfigs.debug
        }
        release {
            mySigningConfigs.release
        }
    }

and put the signingConfigs block at the top of the android block

i.e

android {
  signingConfigs {
    ...
  }

  defaultConfigs {
    ...
  }

  buildTypes {
    ...
  }
}

in my case the other answers didn't help. But moving the signingConfigs from the ext section (probably of your root gradle file) directly to the android block of the module gradle worked. So try the following:

Within the android block add

signingConfigs {
        // optional read your properties with the signingConfig data
        // but keep in mind that you may have to adapt your file paths
        release {
            keyAlias "<keyAliasValue>"
            keyPassword "<keyPasswordValue>"
            storeFile file('<keyStoreFileName>')
            storePassword "<keyStorePasswordValue>"
        }
    .
    .
    .
    }

Within the buildTypes -> release section you can keep your assignment of the concrete signingConfig

buildTypes {

        release {
            signingConfig signingConfigs.release
        }
    .
    .
    .

Then you may have to adapt your paths (localProps and store file) from

rootProject.file('local.properties')
storeFile file('carrierKeystore.jks')

to

// adapt to new path of the files 
rootProject.file('../local.properties')
storeFile file('../carrierKeystore.jks')

There must be a signingConfigs block in your andorid block. like this

 signingConfigs {
    release {
        appSigningConfigs.release
    }
}

defaultConfig {
    ...
    signingConfig signingConfigs.release
Related