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
  • 6,874
  • 14
  • 40
  • 65

10 Answers10

8

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
  • 48,344
  • 9
  • 130
  • 112
4

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
  • 60
  • 4
2

Install Java jdk file in your system and add environment variable path of jdk-19/bin . By this method I can fix my issue

1

After searching everywhere even in youtube comments I found out that you need to go to the directory C:\Program Files\Android\Android Studio\jre and hold Shift + right click, then click on open PowerShell window in the menu appeared. After that, you will have to write .\ before actually pasting the keytool line command. Like the code below :

.\keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias
Aymane
  • 11
  • 3
1

I had the same issue ,here what I did to solve it:

  1. open cmd "NOT windows power shell"
  2. run "flutter doctor -v"
  3. at => "Java binary at:" there is a path like this one "C:\Program Files.Android\Android Studio\jre\bin\java", remove the java word so it will be like this "C:\Program Files\Android\Android Studio\jre\bin"
  4. run cd "your path from step 4" (in my case it was "C:\Program Files\Android\Android Studio\jre\bin")
  5. run the command "keytool -genkey -v -keystore %userprofile%\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload"
  6. I recommend watching this video "https://www.youtube.com/watch?v=g0GNuoCOtaQ" start at 4:53
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
saleem
  • 11
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 09 '22 at 21:04
  • Now this is awesome man. – Kimanthi K. Nov 10 '22 at 10:40
1

I had the same problem, here's what solved it.

  • run the command "flutter doctor -v"

  • under Android toolchain locate and copy the directory like the one below:

    C:\Program Files\Android\Android Studio\jre\bin\java

  • Open another cmd window as administrator, then run the command, cd "the directory you copied" like below: (make sure you delete the java and the \ first)

    cd C:\Program Files\Android\Android Studio\jre\bin

  • run the command below and fill in the prompts that follow

    keytool -genkey -v -keystore test.keystore -alias testkeystore -keyalg RSA -keysize 2048 -validity 10000

  • then finally run the command below to get the certificate fingerprints

    keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%.android\debug.keystore

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.

0

I made several mistakes before finding this solution. Adding to Olaleye's answer, first we need to find the Java folder containing the keytool.exe (use Visual Studio terminal to get the path using this command:

flutter doctor -v

Copy paste the path to File Eksplorer and run CMD terminal inside the folder Java, with command copy pasted from Google

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

Before I falsely copy paste the command including backslash symbol inside it just what it shown in the Google page, thus the terminal doesn't know it.

Then enter default password: android We will get details of SHA1 and SHA256.

vegatroz
  • 36
  • 6
0

Add the Java JDK to your path

On Windows, open Start and search for "Edit environment variables for your account." Under "User variables for {your account name}," double click on the Path entry, and paste the location of your Java JDK path. For me, the default wasC:\Program

C:\Program Files\Java\jdk1.8.0_351\bin

I would suggest that you seaarch by C:\Program Files\Java\ and click on the folder that starts with jdk, open it, and head to the bin. Copy the path, create a new entry below the last entry, and paste it. Make sure to press OK on all windows, and try the command again on the CMD.

0

You should add java path to windows environment variables for keytool to work.

In Android studio, the java location is is C:\Program Files\Android\Android Studio\jbr\bin(if android studio is installed in C), and you should add java path to windows environment variables.

So to verify the java path, firt run flutter doctor -v in terminal and copy the java binary location. for me it was : C:\Program Files\Android\Android Studio\jbr\bin

Then add this location to path variable of system environment variable.

After adding the java path, open command prompt and type the keytool -genkey, you will see that keytool is recognized now.

Notice that you can access keytool command from cmd now, and if you want to use keytool command from android studio terminal, you should type the full path to java according to flutter docs

Zahra
  • 2,231
  • 3
  • 21
  • 41