How to add SHA-1 to android application
Asked Answered
N

20

129

I'm trying to create a dynamic link in Firebase, when I'm selecting the android app, it shows an error saying "Add SHA-1 to this android app", I've already added a credential, but I'm not sure how exactly do I "add SHA-1 to the app"

How is this done?

Norvall answered 25/8, 2016 at 11:55 Comment(4)
Check this to get SHA-1 key from your android studio and add it to your firebase projectHelgahelge
I already got the SHA-1 key, but I don' know how to add it to my firebase projectNorvall
for Android Studio 4.2 see https://mcmap.net/q/103745/-android-studio-4-2-doesn-39-t-show-signing-report-in-the-gradle-barSynaeresis
#3 worked for me --- devopsschool.com/blog/…Nexus
Z
190

SHA-1 generation in android studio:

change firebase project setting

Press add fingerprint button


  1. Select Gradle in android studio from right panel

  2. Select Your App

  3. In Tasks -> android-> signingReport

Double click signingReport.

How to get sha1 fingerprint


You will find the SHA-1 fingerprint in the "Gradle Console"

Add this SHA-1 fingerprint in firebase console

Add SHA1 fingerprint

Zoom answered 25/8, 2016 at 12:6 Comment(10)
remember in the output of signing report copy both the release and debug sha1.Kosher
Couldn't get SHA.Brander
well, it took me some time to find the "Select gradle" because the panel was in the right size. :))))Arguseyed
Android Studio 3.3: Click on the elephant icon in the Gradle panel, select the project, type in the Command line: "signingReport", click OKArdys
This totally worked, but Android Studio saw fit to switch my default configuration to creating a signing report instead of running the app. Just a heads up in case running the app breaks for you after finding this value.Applicant
Can't find: "Select Gradle in android studio from right panel"Killarney
The answer gives you the debug key, check this answer if you are using another key for production #38297993Alphitomancy
For anyone searching the gradle option,A button "Gradle" is placed tilted vertically on the right side of the window.Narcoanalysis
I didn't find debug sha1. I only see md5, sha1, sha256.Bicephalous
this works but is it the same sha1 that's used in production or its for debug purposes only??Obduliaobdurate
K
180

If you are using Google Play App Signing you need to use the SHA1 from google play since Google will replace your release signing key with the one on googles server

enter image description here

Kosher answered 24/3, 2018 at 12:45 Comment(5)
This needs to be a lot higher. I totally missed that my key is just for uploading and then google resigns it on its own. Took me better part of a morning to realize thisKiblah
Really helpful! The Google App Signing SHA1 has to be added to the list of SHA1's on your services.Rakel
Lifesaver! This should be highlighted in the Google App Bundle documentation. They mention it under Tips and Best Practices at the bottom of the page. However, it is unclear what is required and how to implement.Rurik
Had to use upload key certificate's SHA-1 and SHA-256. Thanks btw.Sharasharai
Would be helpful to mention where you can find that in google play: On the left hand side in play.google.com/console go to Release > Setup > App Integrity then click the App Signing tabAdalineadall
C
58

Alternatively you can use command line to get your SHA-1 fingerprint:

for your debug certificate you should use:

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

you should change "c:\Users\user" with the path to your windows user directory

if you want to get the production SHA-1 for your own certificate, replace "C:\Users\user\.android\debug.keystore" with your custom KeyStore path and use your KeystorePass and Keypass instead of android/android.

Than declare the SHA-1 fingerprints you get to your firebase console as Damini said

Cm answered 25/8, 2016 at 12:15 Comment(1)
You need to CD to the java bin folder for keytool to work. For me it was, C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin although you might have a general java edition installed directly in C:\Program Files\Java\...Encyclopedic
A
45

MacOS just paste in the Terminal:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android
Ardys answered 25/9, 2018 at 12:22 Comment(2)
work for me , thank ..Re
can we add multiple SHA-1 to firebase for example one for debug and other for production?Rumph
C
36

for Updated Android Studio(12 May 2021)

  1. Click on Gradle right side
  2. Click on the elephant icon and type the command
gradle signingReport

press Enter

Now, you will see BUILD SUCCESSFUL in the Run window that you can open from bottom just scroll that window upward and you will find your SHA1 key there. Add this key to firebase

  1. In your Project settings, go to the Your apps card.
  2. Select the Firebase Android app to which you want to add a SHA fingerprint.
  3. Click Add fingerprint.
  4. Enter or paste the SHA fingerprint, then click Save.

At last, while running your App please check you change the run configuration to app else only the signingReport Task would be running again and again.

Concerted answered 12/5, 2021 at 7:7 Comment(3)
thanks its work...thanks for last linePeristalsis
This creates multiple SHA fingerprints for me. Which one should I chooseNascent
ideally, you should get two fingerprints SHA1 and SHA256. Do you have multiple modules in the project? else share some more detailsConcerted
V
16

If you are using Google Play App Signing, you don't need to add your SHA-1 keys manually, just login into Firebase go into "project settings"->"integration" and press a button to link Google Play with firebase, SHA-1 will be added automatically.

Varix answered 6/9, 2019 at 4:55 Comment(3)
As we know its totally fine to link Firebase and Google Play, this is a super easy way to get rid of the SHA generation and integration steps. Within a minute i was able to make my Live app's google sign in bug go away. Thanks.Palstave
I am using phone number OTP firebase authentication in my app so i added my project in the firebase console and also added SHA-1 & SHA-256. Then i uploaded my project to Google Play Store and link it with my project in the firebase. Now, SHA-1 on the Google Play Store is different than the firebase one. Is it a problem ?? Thank youPolypody
If that sha was added during firebase integration with google play, that sha should be right.Varix
M
15

Run this command from your android directory.

./gradlew signingReport 

If you're not in the android directory already, run this instead:

cd android && ./gradlew signingReport
Musso answered 30/5, 2021 at 8:20 Comment(1)
This is a good answer because the command displays the fingerprints for all of the app's Build Types and FlavorsHumiliating
F
9

Just In case: while using the command line to generate the SHA1 fingerprint, be careful while specifying the folder path. If your User Name or android folder path has a space, you should add two double quotes as below:

keytool -list -v -keystore "C:\Users\User Name\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Freemasonry answered 13/12, 2017 at 0:7 Comment(0)
G
7

Try pasting this code in CMD:

keytool -list -v -alias androiddebugkey -keystore  %USERPROFILE%\.android\debug.keystore
Godlike answered 8/4, 2018 at 5:56 Comment(2)
what is the password?Osculum
it is your mac's passwordManzanilla
C
6

For linux Ubuntu Open Terminal and Write :-

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
Cymbiform answered 10/7, 2020 at 10:1 Comment(0)
P
5

On Windows, open the Command Prompt program. You can do this by going to the Start menu

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

On Mac/Linux, open the Terminal and paste

   keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
Photomural answered 18/5, 2019 at 10:48 Comment(0)
D
4

linux os terminal run this :

  keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass androi
Drawplate answered 15/5, 2019 at 1:15 Comment(0)
M
3

when I generate sha1 key using android studio

Gradle -> Tasks -> android-> signingReport and double click

That sha1 key is worked in debug mode but not worked when i build singed APK

so I generated sha 1 key using cmd it work

  • go to java\jdk version\ bin folder

example

C:\>cd C:\Program Files\Java\jdk1.8.0_121\bin

and type

keytool -exportcert  -keystore {path of sign jks key } -list -v

example

keytool -exportcert  -keystore F:\testkey\damithk.jks -list -v
Moonfish answered 13/5, 2020 at 6:56 Comment(0)
T
1

Instead Of Writing Command, You can Follow the Following Steps For Copy SHA

  1. Open Android Studio
  2. Open Your Project
  3. Click on Gradle (From Right Side Panel, you will see Gradle Bar)
  4. Click on Refresh (Click on Refresh from Gradle Bar, you will see List Gradle scripts of your Project)
  5. Click on Your Project (Your Project Name form List)
  6. Click on Tasks/Android
  7. Double Click on signingReport (You will get SHA1 and MD5 in Run Bar).
Trachytic answered 4/4, 2021 at 10:0 Comment(0)
T
1

Run this command

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
Tree answered 28/9, 2022 at 10:13 Comment(0)
C
1

From your project directory for example:

E:\practice\firebase_auth_app>

Write:

cd android

And it must be like this example: E:\practice\firebase_auth_app\android>

and then write:

./gradlew signingReport
Cacus answered 17/7, 2023 at 10:14 Comment(1)
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.Alberik
S
0

Open a terminal and run the keytool utility provided with Java to get the SHA-1 fingerprint of the certificate. You should get both the release and debug certificate fingerprints.

To get the release certificate fingerprint: keytool -exportcert -list -v \ -alias -keystore

Streamliner answered 11/8, 2019 at 18:39 Comment(0)
J
0

Easiest and the best option, just open root directory in Command prompt and run "gradlew signingReport" this command.

Jadajadd answered 14/3, 2022 at 4:19 Comment(0)
C
0

To get the release certificate fingerprint, follow this easy detailed step.

Right click on your

android folder

add new file

name it 'key.properties'. (without the single quotation of course)

add this lines

storePassword=any unique password

keyPassword=re-enter unique password

keyAlias=upload

storeFile= we'll put this later on

On your terminal, add the following and Continue.

On Mac/Linux

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

On windows

keytool -genkey -v -keystore c:\Users\USER_NAME\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

On password, enter the unique store password you put. On certificate information, just leave it blank and Continue. At the end, type yes to confirm your information and Continue.

Go to the specified path where your upload-keystore.jks file is put, copy the file or move it to your project. Specifically under this folder.

android/app

Go back to your key.properties file and specify where the upload-keystore.jks path is under storeFile. i.e.

../app/upload-keystore.jks

Go to

android/app/build.gradle

On the file, click

Open for Editing in Android Studio

New Window

On the new window terminal, add

./gradlew signingReport

and Continue.

Search for the results where both the variant and the config are

release

Under that, that's your release keys.

Chanson answered 24/3, 2022 at 16:23 Comment(0)
C
0

For debugging apk in android studio go to terminal and type:

cd app/build/outputs/apk/debug

then type:

keytool -printcert -jarfile app-debug.apk

You will get your SHA1 and SHA256 there.

Change path for release with debug.

Convocation answered 6/12, 2022 at 11:7 Comment(1)
Use code blocks for describing any commands in ternimalDari

© 2022 - 2024 — McMap. All rights reserved.