androidflutterkeytoolandroid-keystore

keytool Unable to locate a Java Runtime


I'm trying to set a Google Auth platform client ID for Android for my Flutter application in order to use google_sign_in.

For that, I need to get the SHA-1 certificate fingerprint. The command suggested by https://console.cloud.google.com/ is:

keytool -keystore path-to-debug-or-production-keystore -list -v

When I run it, I get

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

I remember keytool and being able to run. What is happening?


Solution

  • From the Flutter documentation:

    The keytool command might not be in your path—it's part of Java, which is installed as part of Android Studio. For the concrete path, run flutter doctor -v and locate the path printed after 'Java binary at:'. Then use that fully qualified path replacing java (at the end) with keytool. If your path includes space-separated names, such as Program Files, use platform-appropriate notation for the names. For example, on macOS and Linux use Program\ Files, and on Windows use "Program Files".

    The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12.

    Running

    flutter doctor -v
    

    prompted:

    [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.7s]
        • Android SDK at xxx
        • ...
        • Java binary at: /path/to/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • ...
    

    Running

    /path/to/bin/keytool -keystore path-to-debug-or-production-keystore -list -v
    

    worked.