14

I have a big issue when I come to sign my application: I have set the signing configuration in accordance with the doc:

signingConfigs {
    release {
        storeFile file("lomapnew.keystore")
        storePassword "myPassword"
        keyAlias "myAlias"
        keyPassword "Something...."
    }
}

But I still get this error message: "The signing configuration should be specified in Gradle build scripts"

enter image description here

Jonik
  • 80,077
  • 70
  • 264
  • 372
Waza_Be
  • 39,407
  • 49
  • 186
  • 260

3 Answers3

26

I'm going to go out on a limb and guess that you haven't set the signing configuration for the release build type. The debug build type is automatic, so it's not obvious that this is a necessary step for all other build types, including release.

You can apply the signing config like so:

android {
    signingConfigs {
        // It's not necessary to specify, but I like to keep the debug keystore
        // in SCM so all our debug builds (on all workstations) use the same
        // key for convenience
        debug {
            storeFile file("debug.keystore")
        }
        release {
            storeFile file("release.keystore")
            storePassword "myPassword"
            keyAlias "myAlias"
            keyPassword "Something...."
        }
    }

    buildTypes {
        /* This one happens automatically
        debug {
            signingConfig signingConfigs.debug
        }
        */
        release {
            signingConfig signingConfigs.release
        }
    }
}
Krylez
  • 17,414
  • 4
  • 32
  • 41
  • can you tell me where the `release.keystore` file should be located in order for file("release.keystore") to work? – Bhargav Jan 27 '16 at 03:47
  • @Bhargav The file method is relative to the project root. The keystore live anywhere in your project as long as you update the path in your build file. https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#file(java.lang.Object) – Krylez Jan 27 '16 at 16:28
  • Is it wise to backup keystore files along with your repository in git privately? – Bhargav Jan 28 '16 at 04:32
  • I wouldn't put your release in a git repo, but it's a judgement call. The problem is that it's essentially a one-way trip. With the way git history works, it's easy to recover deleted files. If you ever wish to open source the project, you might accidentally expose a long deleted release key. – Krylez Jan 28 '16 at 19:06
4

I like to keep passwords out of my build file. Hence I create a properties file that I load with

def keystorePropertiesFile = rootProject.file("./local.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

Then I define signingConfigs like so:

   signingConfigs {
    releaseSigning {
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['keystore.live.storepassword']
        keyAlias = keystoreProperties['keystore.live.keyalias']
        keyPassword = keystoreProperties['keystore.live.keypassword']
    }
    debugSigning {
        storeFile file(keystoreProperties['storeFile'])
        storePassword keystoreProperties['keystore.debug.storepassword']
        keyAlias = keystoreProperties['keystore.debug.keyalias']
        keyPassword = keystoreProperties['keystore.debug.keypassword']
    }
}

This doesn't work well with the menu option "create Signed apk" so I create flavors:

    productFlavors {
    mydebug {
        signingConfig signingConfigs.debugSigning
    }
    myrelease {
        signingConfig signingConfigs.releaseSigning
    }
}

and now the signingconfigs work with the run button on the toolbar. For a default keystore the local.properties looks like

ndk.dir=/opt/sdk/ndk-bundle
sdk.dir=/opt/sdk
storeFile=/home/christine/.android/debug.keystore
keystore.debug.storepasswd=android
keystore.debug.keyalias=androiddebugkey
keystore.debug.keypassword=android
keystore.live.storepasswd=android
keystore.live.keyalias=androiddebugkey
keystore.livetest.keypassword=android

In your Jenkins build script, you need to create a symbolic link from local.properties to where the properties file is on your build server.

Christine
  • 5,617
  • 4
  • 38
  • 61
  • How can I use this in my CI? – Fadel Trivandi Dipantara Apr 08 '19 at 07:04
  • If you get the error message "path may not be null or empty string. path='null'" make sure you're targeting the right local.properties file. There are one in the app path, and one in the project path. "./local.properties" targets the project file, and you might have entered the information in the app file. Just move the information to the project one and the project should run! – Joel Broström Jan 07 '21 at 10:47
0

Answer is already given but i would like to highlight the other ways also, We can specify the information manually like below where we have to specify full path to our keystore location like this

signingConfigs {
    release {
        storeFile file('O:/Android/Projects/yourKeyStore.jks')
        storePassword "qwerty"
        keyAlias "yourProjectKeyAlias"
        keyPassword "ProjectKeyPassword"
    }
}

This can also be specified in Signing Report if you go in

File-->Project Structure

Choose your project app module and select the signing report where you can fill up the information and it will automatically add previous release information in the gradle file.

Finally you just have to add

signingConfig android.signingConfigs.release

in the buildTypes {...} section. That will complete the signing procedure.

Purvik Rana
  • 193
  • 2
  • 11