6

trying to build release for android. I ran keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key in the vscode terminal but I get this error

keytool : The term 'keytool' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -val ...
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (keytool:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I ran flutter doctor -v and get thisJava binary at: C:\Program Files\Android\Android Studio\jre\bin\java use the path and replace java with keytool(as in the documentation) but still get error. what do I do

Norbert
  • 5,474
  • 14
  • 35
  • 60

3 Answers3

6

Try running it from a normal Windows Command Prompt

D:\temp>"c:\Program Files\Android\Android Studio\jre\bin\keytool.exe" -help
Key and Certificate Management Tool

Commands:

 -certreq            Generates a certificate request
 -changealias        Changes an entry's alias
 -delete             Deletes an entry
 -exportcert         Exports certificate
...

Also, on Windows, you can't use ~/. Change that to a Windows style path like C:\Users\Norbert\keys, or wherever you want to keep the keystore.

Richard Heap
  • 41,090
  • 7
  • 110
  • 94
3

Create a keystore If you have an existing keystore, skip to the next step. If not, create one by running the following at the command line:

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

Note: Keep this file private; do not check it into public source control.

Note: keytool may not be in your path. It is part of the Java JDK, which is installed as part of Android Studio. For the concrete path, run flutter doctor -v and see the path printed after ‘Java binary at:’, and then use that fully qualified path replacing java with keytool.

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/user name/key.jks

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
    }
}

Check the Description of this Tutorial: https://www.youtube.com/watch?v=nGvPNG-f1-o

OR Generate key using a tool

Download app Signing tool from : https://shatter-box.com/knowledgebase/android-apk-signing-tool-apk-signer/

Go To the Directory Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java

Then type cmd and Enter enter image description here

Follow Along to the video tutorial to generate the key, place the key anywhere you want then follow the next tutorial to wrap the key with app with the 1st tutorial.

Yash Singh
  • 50
  • 4
0
  1. Check JDK is configured properly in system or not
  2. If Java is configured properly, check Andriod SDK is installed properly or not
  3. If Android SDK is installed, then run below command in Command Prompt,

keytool -list -keystore %USERPROFILE%\.android\debug.keystore

This is a debug certificate that we can use in FireBase.