Generate SHA-1 for Flutter/React-Native/Android-Native app

185,428

Solution 1

TERMINAL

Go to the project folder in the terminal.

Mac keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

Windows keytool -list -v -keystore "\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Linux keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

GUI Android Studio.

  1. Select android/app/build.gradle file and on the right top corner click "Open for Editing in Android Studio"

enter image description here

  1. Open Gradle panel and double click on "SigninReport",

see Android studio Gradle Tab

enter image description here

  1. That's it! If you use Firebase - add these 2 keys there. You should add both keys, otherwise, without the release key, Google login will not work on the devices.

enter image description here

Solution 2

This is the easiest way-

  1. Open Android Studio

  2. Open Project

  3. Reveal android folder

  4. Right click "gradlew" file and select Open in Terminal -

Open in Terminal

  1. Go to the terminal view and paste: gradlew signingReport

(edit based on Venkat D. suggestion below: on unix-based systems like mac, you need to specify the current directory like this- ./gradlew signingReport)

Paste

  1. Press enter and scroll to "Variant: debug" to get the SHA1 key

Scroll to key

  1. Copy and use wherever you need it, Good Luck!

Solution 3

You won't find a gradle window view in flutter project, so here is a solution for that.. In command prompt navigate to bin folder of jdk and run this command

keytool -list -v -keystore "C:\Users\yourusernamehere\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

change user name in path

Solution 4

I partially agree with Rishab answer, but what we can do is

and this approach works with all flutter/React-native/Android ....

Navigate to Android folder inside project, there is gradlew file. so we can use this like :

gradlew signingReport 

in Mac

./gradlew signingReport

in my case i use it like :

D:\flutter\flutter_app\android>gradlew signingReport

Project Architecture is :

enter image description here

Solution 5

so if you are using an android studio or VS code it's work both of them

=> Open Terminal

=> cd android

enter image description here

=> signingReport

enter image description here

and the final output like this as given in the image below choice your SSH key in at the place of here is your SSH key

enter image description here

in the above output, image is shown in dummy data I change some of the fields just because of security purpose

Edit: for mac

./gradlew signingReport
Share:
185,428
Joseph Arriaza
Author by

Joseph Arriaza

I am a full stack developer that have knowledge in a lot of technologies, like front end frameworks, like Angular, AngularJS, ReactJS, etc, also I have a knowledge using back end technologies, building APIs using Java, PHP & C#. In my current work, we give services to companies in the US, so far, I have worked for Telecom Service Bureau building APIs and Front End interfaces, and also I work for Front Stream giving support to its system.

Updated on February 07, 2022

Comments

  • Joseph Arriaza
    Joseph Arriaza about 2 years

    I'm trying to generate a SHA-1 for a Flutter app, for Android studio to support Google Sign in, but I don't know how to do that, I saw some posts that indicate to run a command, but there I need a jks file I guess, and flutter doesn't create that.

    Could someone help me?

  • temirbek
    temirbek about 5 years
    it takes time for configuring process
  • Vikas Jangra
    Vikas Jangra over 4 years
    Worth mentioning that on unix-based systems like mac, you need to specify the current directory like ./gradlew signingReport
  • Marco Alves
    Marco Alves over 4 years
    @Mattias that was one of the best comments i have ever seen here!
  • BIS Tech
    BIS Tech over 4 years
    Is it want to add all sha key to firebase? and after added sha, is it need to replace google-service.json file?
  • sh0umik
    sh0umik over 4 years
    The Only Detailed Solution that is working for my flutter project. Thank you a lot <3
  • Dani
    Dani over 4 years
    I cannot see the "Open for Editing in Android Studio" option
  • EslamWael74
    EslamWael74 over 4 years
    ./gradlew signingReport
  • G.Busato
    G.Busato over 4 years
    Easyest solution by far ! once you will have enter ./gradlew signinReport, the SH1 key will be prompted
  • awaik
    awaik about 4 years
    In this case on mac you can use keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
  • awaik
    awaik about 4 years
    for mac command is keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
  • giorgio79
    giorgio79 about 4 years
    Should be the accepted asnwer for Flutter projects :)
  • Ananta Prasad
    Ananta Prasad about 4 years
    Perfect answer for Flutter
  • Dean Villamia
    Dean Villamia almost 4 years
    - the simpler the better <3
  • kokoko
    kokoko almost 4 years
    In my case it was "import Gradle project" for my Flutter app. But had to wait for indexing a bit.
  • Zephania Mwando
    Zephania Mwando almost 4 years
    Worked like magic, only I had a hard time figuring out on the second step opening Gradle yet it is on the right android studio by default. I hope that helps someone.
  • August Kimo
    August Kimo over 3 years
    the ./isn't needed for me in Windows. This works using gradlew signingReport
  • devu mani
    devu mani over 3 years
    Also, you can directly open the android(project name -> android) as an android project
  • William Herrmann
    William Herrmann about 3 years
    For those of us that get an error about JAVA_HOME not being set, I updated my environment variables and added a System variable named JAVA_HOME set to C:\Program Files\Android\Android Studio\jre. Then I updated my Path variable and added %JAVA_HOME%\bin. Then this answer worked for me.
  • NullByte08
    NullByte08 about 3 years
    If you cannot see the "Open in Android Studio" option, close your Flutter project. In Android Studio -> Open the android module of the flutter project in Android Studio from its path.
  • Dani
    Dani about 3 years
    The Gradle Console tab has been replaced by "Build" in Android Studio 3.1, accessible from View -> Tool Windows -> Build.
  • Jay Tillu
    Jay Tillu about 3 years
    This one give me the debug key. How can I get the release key. So that I can use it for production.
  • Jay Tillu
    Jay Tillu about 3 years
    This one gives me the debug key. How can I get the release key? So that I can use it for production.
  • Shishir
    Shishir almost 3 years
    Thank you this helps!
  • Bhargav Sejpal
    Bhargav Sejpal almost 3 years
    ./gradlew signingReport
  • Eric Aya
    Eric Aya almost 3 years
    Same solution already posted in other answers such as stackoverflow.com/a/58518934/2227743
  • Saiful Islam
    Saiful Islam almost 3 years
    this is one of the easy solutions out there. thank you. upvoted
  • Vaishnavi Sood
    Vaishnavi Sood almost 3 years
    Thank you, none of the answers were working, I was disappointed, but at last this worked.
  • nipunasudha
    nipunasudha almost 3 years
    this is the best , the most elegant & fool proof solution
  • Shreyansh Sharma
    Shreyansh Sharma over 2 years
    One of the best answers I have ever seen.
  • KYL3R
    KYL3R over 2 years
    @WilliamHerrmann - I got the JAVA_HOME error, too, but Android Studio told me to run it using ctrl+return which runs it in the IDE instead of the terminal - that worked for me, too.
  • leylekseven
    leylekseven over 2 years
    For ubuntu - android studio correct command or usage; right cicl to project/android/gradlew "run gradlew option> after that in below terminal screen, press up keyword and use; /bin/bash "your android studio folders path"/AndroidStudioProjects/project_folder/android/gradlew signingReport
  • malik kurosaki
    malik kurosaki over 2 years
    work for me ,flutter on vscode "cd android && ./gradlew signinReport"
  • Choy
    Choy over 2 years
    'keytool' is not recognized as an internal or external command, operable program or batch file.
  • Dinith Herath
    Dinith Herath about 2 years
    This solved the API exception PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
  • mohannadalnono
    mohannadalnono about 2 years
    that's work, please add linux command to your answer so it'll benefit more people: in linux instead of just type gradlew we write ./gradlew to build. and to get SHA-1 we write: Terminal> ./gradlew signinReport and we could just build and get SHA-1 key with just one command: Terminal> ./gradlew signinReport
  • chrisu.chrisu
    chrisu.chrisu about 2 years
    Why my key is much longer than others. I also would like to achieve auth in flutter with microsoft, stackoverflow.com/questions/71338563/…
  • Anandh Krishnan
    Anandh Krishnan about 2 years
    Happy coding with your 1 k+ reputition
  • Apoorv Pandey
    Apoorv Pandey about 2 years
    @mohannadalnono Updated, and thanks for your input. Please check and correct me if anything is wrong.
  • bbjay
    bbjay about 2 years
    If you can't see gradle tasks in the gradle tool, see this question: stackoverflow.com/questions/67405791/…
  • Sharath B Naik
    Sharath B Naik about 2 years
    You nailed it. I'm linux user. Spent 4+ hours to slove. Finally. Thanks a lot
  • Atish Paul
    Atish Paul almost 2 years
    Update, Now windows users will have to write same as Mac: ./gradlew signingReport