How to add SHA-1 to android application

The question:

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?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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

Method 2

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

Method 3

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

for your debug certificate you should use:

keytool -list -v -keystore C:Usersuser.androiddebug.keystore -alias androiddebugkey -storepass android -keypass android

you should change “c:Usersuser” with the path to your windows user directory

if you want to get the production SHA-1 for your own certificate, replace “C:Usersuser.androiddebug.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

Method 4

MacOS just paste in the Terminal:

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

Method 5

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.

Method 6

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.

Method 7

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:UsersUser Name.androiddebug.keystore" -alias androiddebugkey -storepass android -keypass android

Method 8

Try pasting this code in CMD:

keytool -list -v -alias androiddebugkey -keystore  %USERPROFILE%.androiddebug.keystore

Method 9

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%.androiddebug.keystore

On Mac/Linux, open the Terminal and paste

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

Method 10

For linux Ubuntu Open Terminal and Write :-

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

Method 11

linux os terminal run this :

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

Method 12

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

Method 13

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 javajdk version bin folder

example

C:>cd C:Program FilesJavajdk1.8.0_121bin

and type

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

example

keytool -exportcert  -keystore F:testkeydamithk.jks -list -v

Method 14

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).

Method 15

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

Method 16

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

Method 17

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:UsersUSER_NAMEupload-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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment