Hussein
Hussein

Reputation: 123

How to solve Invalid keystore format?

Execution failed for task ':app:packageRelease'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade com.android.ide.common.signing.KeytoolException: Failed to read key key from store "/Users/husseinawaesha/key.jks": Invalid keystore format

Upvotes: 7

Views: 33869

Answers (10)

dotrinh DM
dotrinh DM

Reputation: 1393

my problem when generate signed APK:

problem

and my solution:

enter image description here

Upvotes: 4

AlanPintor.Tech
AlanPintor.Tech

Reputation: 41

this worked for me.

Delete and Regenerate Debug Keystore The simplest way to resolve this issue is to delete the debug keystore. Android Studio will automatically generate a new one when you build your project again.

  1. Locate the debug keystore. The path is usually C:\Users\Your_Username.android\debug.keystore on Windows.
  2. Delete the debug.keystore file.
  3. Rebuild the project in Android Studio. A new debug.keystore should be generated automatically.

Upvotes: 3

Gursimran singh
Gursimran singh

Reputation: 1

I had the exact same problem, for me the solution was just to update the java version and then create new keystore from that new version and thankfully the keystore it created was compatible with the build tools version 33.0.2 which I was using to sign apk.

Upvotes: 0

Martin Braun
Martin Braun

Reputation: 12589

The embedded Java version should always work and not have problems with the keys:

Embedded JDK version

For some reason this was set to "11" above, it was the same version, but reported problems. In the attempt to find the right version, I got this error reported by OP, though. I think the embedded JDK version is the recommend one.

Upvotes: 0

Grant
Grant

Reputation: 6329

I ended up getting the Zulu Java version because apparently it works better with Macbook M1.

Install SdkMan from sdkman.io

Then to switch your Java version:

sdk install java 11.0.13-zulu
sdk use java 11.0.13-zulu

(You can always use sdk java list to see what you have installed & what you can install etc.)

Then the most important part, ensure your Android Studio is using that Java version - go into Preferences (Android Studio > Settings) and search Gradle, then go to where it says "Gradle JDK" & select the right one.

android studio gradle settings

Upvotes: 3

Moaz Rashad
Moaz Rashad

Reputation: 1075

I had the same problem because I was using the android studio with the default JDK and when I changed the JDK to a different one and tried to run the app using the terminal it always failed.

Solution:

  • navigate to /Users/"username"/.android/
  • remove the debug.keystore using "rm -rf debug.keystore"
  • run this command to generate new debug.keystore:
    "keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug"
  • navigate back to your app folder and run "./gradlew build"

Upvotes: 0

oblomov
oblomov

Reputation: 544

It's probably a conflict between Java versions used by Android Studio and Keytool. To solve it, re-create the keystore using Andtroid Studio's JDK.

  1. Remove or rename your current keystore (.jks file)

  2. Check Android Studio's JDK

flutter doctor -v

It'll be something like

Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
  1. Navigate to bin folder where java is located (your path may differ)
cd /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/
  1. Create new keystore:

https://flutter.dev/docs/deployment/android#create-an-upload-keystore

Upvotes: 2

Akbar Masterpadi
Akbar Masterpadi

Reputation: 1196

please create a key store by this code

 keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

Reference the keystore from the app

Create a file named appdir/android/key.properties that contains a reference to your keystore:

storePassword=password from previous step
keyPassword=password from previous step
keyAlias=key
storeFile=location of the key store file, e.g. 
/Users/username/key.jks

add this on app level gradile

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

  signingConfigs {
  release {
    keyAlias keystoreProperties['keyAlias']
    keyPassword keystoreProperties['keyPassword']
    storeFile file(keystoreProperties['storeFile'])
    storePassword keystoreProperties['storePassword']
     }
       }
     buildTypes {
     release {
      signingConfig signingConfigs.release
     }
   }

Upvotes: 4

Mick
Mick

Reputation: 681

This command line statement from the Play Console Help pages will generate an Upload Keystore, you just have to substitute your own alias and supply the path to keytool...

keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks

However, while it does ask for a Store password, it does not ask for a Key password. If you are like me new to this you may not notice, and later on when you have to input a Key Password you might find yourself scrambling thru notes trying to find where you wrote it down. If you type something like keypassword as a guess it will respond with Invalid keystore format.

It is better to use the Android Studio process to generate an Upload Keystore rather than this command line statement.

Upvotes: 5

Soo Xiao Tong
Soo Xiao Tong

Reputation: 214

You need to generate the key with android studio.

I got the same issue, the keytool on my M1(OpenJDK) generates invalid key.

Upvotes: 4

Related Questions