android-studiokeystorejks

Why does AndroidStudio fail when Building Signed APK for Google Play (says bad password, but I've confirmed password)?


I have a Keystore (.jks) which I used to sign the previous release of my App (.APK) for Google Play. That was 1 year ago or so.

Now, when I attempt to build and use my keystore, Android Studio gives me the following incorrect error: Could not build signed APK. Keystore was tampered with, or password was incorrect.

Android Studio version information: 
Android Studio Bumblebee | 2021.1.1 Patch 3
Build #AI-211.7628.21.2111.8309675, built on March 16, 2022
Runtime version: 11.0.11+0-b60-7590822 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.11.0-49-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.21-release-334-AS7442.40)
Current Desktop: ubuntu:GNOME

Here is the functionality I'm attempting to run:

Build => Generate Signed Bundle / APK Displays the following screens...

step 1 - build signed apk

step 2 - build signed apk

When I click [Finish] button Android Studio attempts to build & it fails with the error:

Could not build signed APK. Keystore was tampered with, or password was incorrect.

That Is an Incorrect Error

However, that is not correct because I use a password manager to store the password, so I know I have the correct password. I also kept screenshots of the last time I ran this functionality so I could confirm the key alias and it is correct also.

Things I Tried

  1. I tried rebuilding a couple of times & got the error.
  2. I closed & restarted Android Studio & still got the error.

At one point Android Studio crashed with a bug report & I tried again & it failed again.

Why does this error occur?

I discovered some other people reporting what seemed to be an issue with having a password that contained special chars (@ !, etc) at this link.

It does seem to be the same failure, but I finally got it to work & I will post the answer.

Additional Information - Android Studio 09/2023

I'm now running the latest version of Android Studio and posting this update 1 year and 4 months later because I still see the problem where Android Studio tells me that my password is incorrect -- even thought it isn't.

Keep in mind my password for this comes from a password manager and I paste it in -- no typing mistakes or password mistakes.

The Resolution Whenever I attempt to build a signed APK and I get the error, then I simply restart Android Studio and build the signed APK again, paste in the same password and it succeeds.

Android Studio Version Information

Android Studio Giraffe | 2022.3.1 Patch 1
Build #AI-223.8836.35.2231.10671973, built on August 17, 2023
Runtime version: 17.0.6+0-17.0.6b829.9-10027231 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 6.2.0-32-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry:
    external.system.auto.import.disabled=true
    ide.text.editor.with.preview.show.floating.toolbar=false

Current Desktop: ubuntu:GNOME


Solution

  • I started a console window and ran the following against my keystore.

    $ keytool -list -keystore 'fakeNmae.jks' -storepass fake-password-same-one-i-used-in-android-studio

    I saw the details of my keystore printed out in the console:

    Keystore type: JKS Keystore provider: SUN

    Your keystore contains 1 entry

    fake-alias-name, Dec 15, 2019, PrivateKeyEntry, Certificate fingerprint (SHA-256): 63:D3:69:69:39:29:5D:5E:14:20:E1:F6:FA:DF:ED (fake data)

    Warning: The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore fakeName.jks -destkeystore fakeName.jks -deststoretype pkcs12".

    Since I had to supply my password this confirmed that I was indeed using the correct password.

    It also confirms that the keystore was not tampered with (corrupted).

    I was a bit confused at this point.

    Solution

    I started AndroidStudio again & tried it again and it built the signed APK with no problem. I was able to upload it to Google Play.

    Very odd. It seems that listing the details somehow fixed the issue in Android Studio. Would love to hear something about this from someone who might know why.

    Maybe it has to do with that new warning about the PKCS12 format??