14

I'm using gradle (assembleRelease) to generate the release apk.

I have saved the keystore file in project/app/filename.keystore (Within the application)

I have specified details related to signing in gradle.properties file

RELEASE_STORE_FILE=filename.keystore
RELEASE_STORE_PASSWORD=****
RELEASE_KEY_ALIAS=alias
RELEASE_KEY_PASSWORD=****

My build.gradle file has the following related to signing

signingConfigs {
        release {

            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

I have specified signing configurations in the same gradle file as below

 buildTypes {
    release {
        signingConfig signingConfigs.release
    }
 }

However, when I'm trying to create the release build I keep getting following error

Error:Execution failed for task ':app:package<flavor>Release'.
> Failed to read key from keystore

I tried following

  • Giving a wrong password to see if the file can be found.Gives the following error with correct path there for I assume the file can be found.

    Failed to read key from store "": Keystore was tampered with, or password was incorrect

Appreciate your input!

HMK
  • 383
  • 1
  • 5
  • 18
  • 1
    I am having the same problem but have not figured it out yet :( – Markymark Dec 24 '14 at 00:22
  • 1
    I tried signing the APK with Build>Generate Signed APK" in android Studio. Funny thing is the signing is successful. However when I use gradle task "assmbleRelease" I get above error. For now I created a new key to enable automatic deployment during qa. Just a work around until I figure out the solution – HMK Dec 24 '14 at 00:26
  • 2
    @Marky17 and others with the same problem: I was facing this because the "key alias" I typed in didn't exist in the keystore. [This answer](http://stackoverflow.com/a/28119723/1276636) helped me out. – Sufian Mar 10 '15 at 06:23

4 Answers4

26

My problem was that I had entered a random keyAlias. When trying to sign the apk using the IDE (IntlliJ Idea and Android Studio: Build menu -> generate signed APK), by clicking the ellipse button (...) next to the textbox for entering key alias, I found the correct key alias that I had earlier set for my keystore. Double check that you are not entering some ad-hoc random password and keyAlias for your keystore as they should be identical to the password and key alias you set for your keystore when creating it.

If you have forgotten either the password or the key alias, I am afraid you have to create a new keystore as you cannot read your keystore without these. I suggest saving these two properties (and attaching your keystore file) in a password manager like Lastpass, as you need them in future.

Javad
  • 5,755
  • 4
  • 41
  • 51
12

I was using double-quotes with alias and passwords as shown below

storePassword="spass"
keyAlias="kalias"
keyPassword="kpass"

Removing double-quotes solved my problem

storePassword=spass
keyAlias=kalias
keyPassword=kpass
Vasudev
  • 1,936
  • 19
  • 17
6

My problem was that I had extra whitespace in the gradle.properties file. So if you have entries like this:

MYAPP_RELEASE_KEY_ALIAS=my-key-alias(\s)(\r\n)

Make sure there is no leading whitespace for all the entries:

MYAPP_RELEASE_KEY_ALIAS=my-key-alias(\r\n)
Alappin
  • 674
  • 8
  • 9
1

I have not fully fixed this issue, but I think it is related to the following entries in 'Telegram\TMessagesProj\build.gradle':

signingConfigs {
    debug {
        storeFile file("config/release.keystore")
        storePassword RELEASE_STORE_PASSWORD
        keyAlias RELEASE_KEY_ALIAS
        keyPassword RELEASE_KEY_PASSWORD
    }

    release {
        storeFile file("config/release.keystore")
        storePassword RELEASE_STORE_PASSWORD
        keyAlias RELEASE_KEY_ALIAS
        keyPassword RELEASE_KEY_PASSWORD
    }
}

Note that the DEBUG config is set to us a 'release.keystore'.

The passwords and alias are stored in 'Telegram\gradle.properties' and I have had some success by changing these to the ones I use when signing APKs and changing the debug line to point to your own signing key (created through Android Studio).

E.g. Change the line to

debug { storeFile file("path/to/your/signing/key/ApkSigning.jks") ... }

And set the appropriate passwords and alias in the gradle properties file.

Hope that helps.

asnake
  • 11
  • 2