172

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?

Tushar Pandey
  • 4,557
  • 4
  • 33
  • 50
Joseph Arriaza
  • 12,014
  • 21
  • 44
  • 63
  • Here is my solution posted for same question [solution](https://stackoverflow.com/a/53685876/6183464) – Rishab Surana Dec 08 '18 at 18:59
  • The Gradle Console tab has been replaced by "Build" in Android Studio 3.1, accessible from View -> Tool Windows -> Build. – Dani Mar 31 '21 at 09:20

33 Answers33

325

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

awaik
  • 10,143
  • 2
  • 44
  • 50
  • Is it want to add all sha key to firebase? and after added sha, is it need to replace google-service.json file? – BIS Tech Oct 09 '19 at 17:25
  • The Only Detailed Solution that is working for my flutter project. Thank you a lot <3 – sh0umik Oct 14 '19 at 21:38
  • 37
    I cannot see the "Open for Editing in Android Studio" option – Dani Nov 22 '19 at 09:56
  • 3
    In this case on mac you can use keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android – awaik Feb 04 '20 at 05:43
  • 3
    In my case it was "import Gradle project" for my Flutter app. But had to wait for indexing a bit. – kokoko May 09 '20 at 06:39
  • 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. – Zephania Mwando May 14 '20 at 20:02
  • 1
    Also, you can directly open the `android`(project name -> android) as an android project – devu mani Jan 16 '21 at 07:50
  • 2
    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. – NullByte08 Mar 17 '21 at 03:59
  • 2
    The Gradle Console tab has been replaced by "Build" in Android Studio 3.1, accessible from View -> Tool Windows -> Build. – Dani Mar 31 '21 at 09:20
  • This one gives me the debug key. How can I get the release key? So that I can use it for production. – Jay Tillu Apr 24 '21 at 03:51
  • If you can't see gradle tasks in the gradle tool, see this question: https://stackoverflow.com/questions/67405791/gradle-tasks-are-not-showing-in-the-gradle-tool-window-in-android-studio-4-2 – bbjay Mar 24 '22 at 16:30
  • 2
    You nailed it. I'm linux user. Spent 4+ hours to slove. Finally. Thanks a lot – Sharath B Naik Apr 14 '22 at 09:13
  • @Dani You should add `.iml` file in Project android/ folder. Make sure the file name syntax should be _android. – Rohit Bhargava Oct 10 '22 at 06:15
  • 1
    This is the best answer that worked for me. I was distributing the adhoc build for Android using Firebase app distribution and without adding the release SHA-1 fingerprint to Firebase, Google sign in simply wasn't working. Adding both release and debug SHA-1 fingerprints to Firebase console did the trick. Burnt a lot of time trying to figure this out, thanks a lot for the detailed explanation. – GeekyDeveloper Jun 07 '23 at 16:33
259

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 or ./gradlew signingReport if you're using PowerShell or a Unix-based system like mac.

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!
Igal s
  • 2,689
  • 1
  • 10
  • 7
  • 1
    it takes time for configuring process – temirbek Feb 23 '19 at 08:01
  • 5
    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. – William Herrmann Feb 10 '21 at 15:54
  • 2
    This one give me the `debug` key. How can I get the `release` key. So that I can use it for production. – Jay Tillu Apr 21 '21 at 15:21
  • @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. – KYL3R Oct 08 '21 at 07:41
  • 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 – leylekseven Oct 08 '21 at 14:52
  • This solved the API exception *PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)* – Dinith Herath Feb 03 '22 at 19:01
  • Why my key is much longer than others. I also would like to achieve auth in flutter with microsoft, https://stackoverflow.com/questions/71338563/how-to-generate-package-signature-in-flutter-azure-connection-msal – chrisu.chrisu Mar 03 '22 at 15:59
  • Update, Now windows users will have to write same as Mac: ./gradlew signingReport – Atish Paul May 27 '22 at 11:08
  • Best for Flutter projects. Run the command ./gradlew signingReport. to get SHA Key. – Rahul Kushwaha Sep 29 '22 at 07:37
  • 8
    for `WINDOWS` use `./gradlew signingReport` if your using `powershell` – kamasuPaul Oct 30 '22 at 04:27
  • if gradlew command doesn’t work add ./ before the command like: ./gradlew I found the error gradlew command not found and adding ././gradlew works for me – Khurram Mar 28 '23 at 22:08
138

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

Rishab Surana
  • 1,977
  • 1
  • 11
  • 20
111

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

Tushar Pandey
  • 4,557
  • 4
  • 33
  • 50
43

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
Tushar Nikam
  • 1,445
  • 1
  • 14
  • 21
39

run this commend it work any where

in android folder

./gradlew signingReport

for example

PS E:\flutterProject\flutter_app\android> ./gradlew signingReport

some time you not need add ./ just

gradlew signingReport

this work for android studio and cmd and commond prome

Rahman Rezaee
  • 1,943
  • 16
  • 24
18

you can do the same on VSCode, open the folder that contain gradlew for linux and gradlew.bat for windows and run ./gradlew signingReport for Window and run gradlew signingReport for Linux

run ./gradlew signingReport

Mohamed Dernoun
  • 776
  • 5
  • 13
17

1-write those two commands in android studio's or vscode terminal:

cd android
gradlew signingReport

2-wait a bit then scroll up.

in linuix

cd android
./gradlew signingReport
Abdelrahman Tareq
  • 1,874
  • 3
  • 17
  • 32
MD ZDN
  • 209
  • 2
  • 8
15

Simple and easy:

cd android && gradlew signinReport
Code Spirit
  • 3,992
  • 4
  • 23
  • 34
14

For Android Studio 4.2 and Flutter 2.2

Windows:

Open your project open android > gradlew > right click on it and click open in terminal

Like below:

enter image description here

My Project Directory: D:\AndroidStudioProjects\WowTalentNew\android>gradlew

open this in terminal.

After build finished execute this

D:\AndroidStudioProjects\YourProjectDirectory\android>gradlew signinReport

After that you will see the SHA keys

enter image description here

Here's my full CMD screen

Microsoft Windows [Version 10.0.19043.985]
(c) Microsoft Corporation. All rights reserved.

D:\AndroidStudioProjects\WowTalentNew\android>gradlew

> Configure project :app
WARNING: The option setting 'android.enableR8=true' is deprecated.
It will be removed in version 5.0 of the Android Gradle plugin.
You will no longer be able to disable R8

> Task :help

Welcome to Gradle 6.3.

To run a build, run gradlew <task> ...

To see a list of available tasks, run gradlew tasks

To see a list of command-line options, run gradlew --help

To see more detail about a task, run gradlew help --task <task>

For troubleshooting, visit https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 
7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See 

BUILD SUCCESSFUL in 6s
1 actionable task: 1 executed
D:\AndroidStudioProjects\WowTalentNew\android>gradlew signinReport

> Configure project :app
WARNING: The option setting 'android.enableR8=true' is deprecated.
It will be removed in version 5.0 of the Android Gradle plugin.
You will no longer be able to disable R8

> Task :app:signingReport
Variant: debugAndroidTest
Config: debug
Store: C:\Users\apoor\.android\debug.keystore
Alias: AndroidDebugKey
MD5: 2A:97:87:DF:E1:58:D4:9D:E6:65:18:********
SHA1: 4E:0E:D0:F7:68:51:80:47:3E:D1:**************************
SHA-256: 
17:83:42:F4:0E:59:C5:5B:1E********************************************************
BC:79
Valid until: Saturday, November 26, 2050

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

I hope it clears everything, happy coding!

Apoorv Pandey
  • 2,118
  • 2
  • 11
  • 13
  • 1
    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 – mohannadalnono Mar 02 '22 at 12:26
  • 1
    Happy coding with your 1 k+ reputition – Anand Mar 09 '22 at 06:32
  • @mohannadalnono Updated, and thanks for your input. Please check and correct me if anything is wrong. – Apoorv Pandey Mar 10 '22 at 17:48
12

To generate SHA-1 for a Flutter :

1. Locate your android directory inside the console

E:\<appname>\android>

2. After locating to the android folder run this command

./gradlew signingReport

If this won't work and opens a daemon terminal

1. Type signingReport in daemon terminal

daemon> signingReport

This would be taking a bit long time to generate your first SHA-1 as it would be checking for all the firebase dependencies and after that over it generate the SHA-1.

loopassembly
  • 2,653
  • 1
  • 15
  • 22
  • It works, however it generated a debug SHA. How can I generate a release SHA? – Behzod Faiziev Dec 28 '22 at 21:56
  • I could find a release SHA-1 by this video https://www.youtube.com/watch?v=oyJNP3-N838&ab_channel=FlutterMapp – Behzod Faiziev Dec 28 '22 at 21:58
  • Yes, it is solved. Thanks – Behzod Faiziev Dec 29 '22 at 14:59
  • @BehzodFaiziev Thank you for trying out my solution! If it helped you solve your problem, please consider upvoting my answer. Upvotes help to highlight useful and accurate answers, and they help me to contribute more to the Stack Overflow community. Thanks again, and I'm glad that I could help! – loopassembly Jan 01 '23 at 04:46
8

Check this Authenticating Your Client  |  Google APIs for Android

To get the debug certificate fingerprint:

for Mac or Linux

keytool -list -v \ -alias androiddebugkey -keystore ~/.android/debug.keystore

for Windows

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

The default password for the debug keystore is android.

The keytool then prints the fingerprint to the terminal.

Vishal Singh
  • 1,341
  • 14
  • 13
6

1. First Methord just run the below command

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

2. Second Methord

1. Left side open the android folder not the whole project in android studio.

2. Right Side open the file android/app/Tasks/anroid/signingReport

Final this process will take some time and it might be of 5-10 minutes so be patient

enter image description here

Muhammad Tameem Rafay
  • 3,602
  • 2
  • 21
  • 32
5

This solution work for me in MAC os Monterey and Android studio Bumblebee

open the android folder in terminal

right click on Android folder>Open In>Terminal

enter image description here it will open new terminal window and run below command

bash ./gradlew signingreport
R7G
  • 1,000
  • 1
  • 10
  • 15
3

You can generate it even from terminal. Following is for the release mode:

keytool -list -v -keystore keystore_location -alias alias_name

example :

keytool -list -v -keystore /home/user/key.jks -alias alias_name
Newaj
  • 3,992
  • 4
  • 32
  • 50
3

Method 1

  • Make sure java is installed in your system.

enter image description here

Method 2

  • Using Command-line change your username and run the below command
keytool -list -v -alias androiddebugkey -keystore C:\Users\YOURUSERNAME\.android\debug.keystore
  • the default password is android

enter image description here

Swaroop Maddu
  • 4,289
  • 2
  • 26
  • 38
3

go to the android folder in terminal

cd android .\gradlew signingReport

it will generate your SHA1 and SHA256 for you

akash maurya
  • 607
  • 9
  • 16
3

If you have the keystore file, then run keytool -list -v -keystore fileName.jks -alias upload -storepass password -keypass password at the keystore file location...

balu k
  • 3,515
  • 2
  • 14
  • 29
2

First, check which Keystore is being used by your project in

enter image description here

Then use the below command

 keytool -list -v -alias mstoreappsemoAlias -keystore  fluxstorepro/android/app/mstoresemoFile.keystore    

and if you want to generate a hash key for Facebook then use the below command

 keytool -exportcert -alias mstoreappsemoAlias -keystore fluxstorepro/android/app/mstoresemoFile.keystore | openssl sha1 -binary | openssl base64
2

To get generate a SHA-1 key

in the terminal type cd android and change the path then type ./gradlew signingReport

1

Flutter Project Using MAC & VS Code

  • Step One
    Go To the Android Gradle Properties and add this line

https://services.gradle.org/distributions/gradle-6.3-all.zip

enter image description here

  • Step Two Open the Terminal at android Folder of your Projects . then in the terminal type

.\gradlew signinReport

you will get the signing report Like this : enter image description here

1

try writing this in Terminal - For Windows

cd android

gradlew signingReport

Kyoto
  • 308
  • 4
  • 4
1

For Mac Users

If after typing ./gralew signingReport inside android folder gives you this error:

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

Then follow this process:

  1. Run flutter doctor -v
  2. Now inside the Android toolchain copy the location after Java binary at:. It will be something like this: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
  3. Paste it in the project's root location and Replace the java at the end of the above location with keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android.

You are done, you will see the keys now.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Ali Murtaza
  • 414
  • 4
  • 9
1

I'm using a Mac and Android Studio Dolphin 2021.3.1 Patch 1.

None of the answers with visual directions worked for me because when I pressed the gradle/elephant in the upper right hand corner of Android studio, there were only 2 paths MyPojectName/app. Everyone else's has more paths underneath however mines only has 2.

When I pressed the elephant (Execute Gradle Task) and I typed in signingReport nada. I looked through the list but it wasn't there.

When I opened Terminal in Android studio and entered gradlew signingReport nothing found. Then I tried ./gradlew signingReport and still nothing.

Long story short it only took 2 easy steps to find the keys. I first followed this answer:

1- Android Studio/Preferences/Build,Execution,Deployment/Build Tools/Gradle. In the right panel click the Gradle JDK dropdown then select Download JDK

2- After that finished, while in Android Studio I opened Terminal

enter image description here

In there I followed R7G's answer (his answer didn't work at first without step 1) and entered this into terminal:

bash ./gradlew signingreport

And like that, both keys appeared

enter image description here

Another option is to add Gradle either using Homebrew

brew install gradle

or install gradle manually

To find where gradle is located on mac

Another option is to run gradle wrapper and follow the prompts

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0

for linux:

  1. if you are using vscode you can right-click on gradlew->copypath (in my case: /home/alif/Documents/project/flutter/fit_app/android/gradlew)
  2. open your terminal and paste it, don't forget to delete /gradlew
  3. type .../android gradlew signinReport and hit enter

good luck!

Alif Al-Gibran
  • 1,166
  • 1
  • 13
  • 24
0

I found that I needed to check the fingerprint in Google Play Console, since I have Google Play managed app signing.

The ones provided by gradlew did not work for me.

Note that you can put both in Firebase, but you only need one. I just added the SHA1 and Google Sign In began working.

Google Play Console

JVE999
  • 3,327
  • 10
  • 54
  • 89
0

Personally, I went to the terminal then navigated to C:\Program Files\Java\jdk-14.0.2\bin (navigate to your java bin folder).

Next, I ran this command and it worked: keytool -list -v -keystore "%USERPROFILE%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Matthew Trent
  • 2,611
  • 1
  • 17
  • 30
0

gradlew signingReport

Use this command on Terminal which you can find in bottom left corner.

  • 2
    Same solution already posted in other answers such as https://stackoverflow.com/a/58518934/2227743 – Eric Aya May 22 '21 at 16:17
0

You can use one line in terminal

echo y | keytool -genkeypair -dname "cn=Chris, ou=JavaSoft, o=Sun, c=US" -alias business -keypass kpi135 -keystore /working/android.keystore -storepass ab987c -validity 20000
  • dname is a unique identifier for the application in the .keystore
  • cn the full name of the person or organization that generates the .keystore
  • ou Organizational Unit that creates the project, its a subdivision of the Organization that creates it. Ex. android.google.com
  • o Organization owner of the whole project. Its a higher scope than ou. Ex.: google.com
  • c The country short code. Ex: For United States is "US"
  • alias Identifier of the app as an single entity inside the .keystore (it can have many)
  • keypass Password for protecting that specific alias.
  • keystore Path where the .keystore file shall be created (the standard extension is actually .ks)
  • storepass Password for protecting the whole .keystore content.
  • validity Amout of days the app will be valid with this .keystore
chrisu.chrisu
  • 119
  • 2
  • 14
0

Solution for Windows Flutter 2022-23 solution to get SHA-1

First solution:-

  1. In your project terminal type cd android

  2. now you're inside the android folder now type ./gradlew then type

    gradlew signinReport

IF you got this error then try next solution

second solution

  1. Again type cd android in your root project
  2. Now type ./gradlew signingReport

you will surely get SHA-1

0

If you are using flutter I hope it will work for you,

  1. If you are using vs code then open terminal or if you are using other stuff then Goto the project folder and open terminal and past below code

    keytool -list -v -keystore "C:\Users%your user name%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

It's work for me. i think will work for you also.

Azizur Rahaman
  • 181
  • 2
  • 5
-1

Working solution in 2022 for all Android apps including React Native and Flutter. If you need to see SHA-1 certificate code but all other options did not work, you can try this. Suggested solutions like running commands from Command Line and other suggested ways through Android Studio was giving this error: could not open `C:\Program Files\Android\Android Studio\jre\jre\lib\amd64\jvm.cfg'. No need to unistall Java, remove java files or play with system path values as mentioned by others.

Here is how you can get it work:

  1. Find Gradle window on the right panel, inside Android Studio and click on famous Gradle icon enter image description here

enter image description here

  1. Type "gradle signingReport" and wait the process finish. It will print out all SHA-1, SHA-256, MD5 etc for you. enter image description here

Note: If you see this error Task 'signing' is ambiguous in root project... Candidates are... you need to clean the project(Top level menu Build --> Clean Project) first and then run this gradle signingReport again.

Elmar
  • 2,235
  • 24
  • 22
-1

Easy Solution

for windows

  1. cd to android
  2. ./gradlew
mohammed gamal
  • 299
  • 3
  • 4