APK signing error : Failed to read key from keysto

2019-01-08 16:10发布

问题:

I'm developing android app under intellij and gradle. and using following way to generate keystore file:

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

then used the keystore file in build.gradle:

signingConfigs {
    robert {
        storePassword 'robert'
        storeFile file('/Users/bournewang/Documents/Project/android.keystore')
        keyPassword 'robert'
        keyAlias 'mike'
    }
}

when finally trying to generate signed apk file: ./gradlew assembleRelease

it gives the error:

Execution failed for task ':Myexample:packageRelease'.

Failed to read key from keystore

回答1:

Check your keystore file for first, in you example you creating file with name my-release-key.keystore. If its correct and really present in folder Users/bournewang/Documents/Project check alias, in your example it is -alias alias_name, but in config you specified alias mike



回答2:

In order to find out what's wrong you can use gradle's signingReport command.

On mac:

./gradlew signingReport

On Windows:

gradlew signingReport


回答3:

Most likely that your key alias does not exist for your keystore file.

This answer should fix your signing issue ;)



回答4:

Removing double-quotes solved my problem, now its:

DEBUG_STORE_PASSWORD=androiddebug
DEBUG_KEY_ALIAS=androiddebug
DEBUG_KEY_PASSWORD=androiddebug


回答5:

In my case, while copying the text from other source it somehow included the space at the end of clipboard entry. That way the key password had a space at the end.



回答6:

It could be any one of the parameter, not just the file name or alias - for me it was the Key Password.