Faiz Fareed
Faiz Fareed

Reputation: 1548

Mac OS Flutter build appbundle failed: Invalid keystore format

since a week I am trying to create android app bundle from a flutter app and I've followed from Create an upload keystore given official flutter website

in Mac OS I've tried following command in terminal

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

it prompted me to Enter keystore passwordand which I've write android and then Re-enter new password:android after that sequence of questions and answers which I've filled up like as your first and last name?, What is the name of your organizational unit?, What is the name of your organization?, What is the name of your City or Locality?, What is the name of your State or Province?, What is the two-letter country code for this unit?, and finally asked about the information is correct which I replied yes, it made .jks file while prompting like this

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
    for: CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
[Storing /Users/faizfareed/upload-keystore.jks]

after that I've Created a file named [project]/android/key.properties that containing a reference to the keystore with following info in the file

storePassword=android
keyPassword=android
keyAlias=upload
storeFile=/Users/faizfareed/upload-keystore.jks

finally I've Configured gradle [project]/android/app/build.gradle file.

Added the keystore information from properties file before the android block:

   def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
         ...
   }

Loaded the key.properties file into the keystoreProperties object.

Replaced the buildTypes block:

buildTypes {
       release {
           // TODO: Add your own signing config for the release build.
           // Signing with the debug keys for now,
           // so `flutter run --release` works.
           signingConfig signingConfigs.debug
       }
   }

With the signing configuration info:

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

finally when I executed flutter build appbundle command, it giving error like this one

faizfareed@Faizs-MBP building_apk % flutter build appbundle 

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:signReleaseBundle'.                     
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Failed to read key upload from store "/Users/faizfareed/upload-keystore.jks": Invalid keystore format
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 7s                                                      
Running Gradle task 'bundleRelease'...                                  
Running Gradle task 'bundleRelease'... Done                         7.8s
Gradle task bundleRelease failed with exit code 1

for reference I am also attaching Image of the terminal

enter image description here

I've also tried following solution but nothing works for me

Can anyone help me out from this error Invalid keystore formate

Upvotes: 4

Views: 5225

Answers (2)

Steve Keddy
Steve Keddy

Reputation: 1

append -storetype JKS to your keystore command. After Java 8 this was necessary see Java 8 already supports PKCS12 but it is not the default format. If you want to use a PKCS12 keystore with Java 8 you need to pass the parameter "-storetype pkcs12" (see docs.oracle.com/javase/8/docs/technotes/tools/unix/…) and stackoverflow.com/a/11540061/5646962 –

Upvotes: 0

Roy Parejo
Roy Parejo

Reputation: 341

I just have the same error. I had installed JDK from https://docs.oracle.com/en/java/javase/15/install/installation-jdk-macos.html#GUID-2FE451B0-9572-4E38-A1A5-568B77B146DE but it wasn't necessary since Android Studio have it, so I uninstalled it.

I used the next command in terminal

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

I recommended to use the command

flutter doctor -v

to check java path 'Java binary at:' enter image description here

Upvotes: 16

Related Questions