Generate Hash Key for Facebook and SHA-1 Key for Google Maps in Android Studio

Dharmesh Basapati
MindOrks
Published in
3 min readNov 23, 2018

One stop solution for all your key(s) and hashes for using in your Android Studio project.

→ Where to find debug.keystore on different platforms:

On Windows: C:\User\YourUser\.android\debug.keystore

On Mac: /Users/$username/.android

On Linux:- $HOME/.android/

→ Generate SHA-1 Key

There are a couple of ways to generate this:

A) Faster way:

  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 from List (root))
  6. Click on Tasks
  7. Click on Android
  8. Double Click on signingReport (You will get SHA1 and MD5 in Run Tab)
  9. Select the app module from module selection dropdown to run or debug your application

B) With Google Maps Activity:

  1. Open Android Studio
  2. Open Your Project
  3. Click on File menu -> Select New -> Click on Google -> Select Google Maps Activity
  4. A dialog would appear -> Click on Finish
  5. Android Studio would automatically generate an XML file named with google_maps_api.xml
  6. You would get debug SHA1 key here (at line number 10 of the XML file)

Generate Key Hash for Facebook:

In Linux, Open Terminal:

For Debug Build:

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

You will find debug.keystore from “.android” folder copy it from and paste that on the desktop and run above command.

For Release Build:

keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64

NOTE: Make sure In Both case it should ask for the password. If it does not asks for the password that means something is wrong in command.

In Windows, Open Terminal in Android Studio or Command Prompt:

For Debug Build:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Note 1: When it prompts you for a password, type android and hit Enter

Note 2: Navigate in the Command Prompt to the directory where your Android debug.keystore is stored.

Note 3: For Release Build, Just replace the debug.keystore path with your release keystore path and run the above command as usual.

In MAC, Open Terminal:

For Debug Build:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Note 1: When it prompts you for a password, type android and hit Enter

Note 2: Navigate in the Terminal to the directory where your Android debug.keystore is stored.

Note 3: For Release Build, Just replace the debug.keystore path with your release keystore path and run the above command as usual.

That’s it from my side for this kinda guide to let you know about the various ways to generate SHA-1 Key, Key Hash, and where to locate your Android debug.keystore file. Hope you all get some useful information from this.

Share and Spread this post if you know someone who can get some benefit from this.

Kudos !!!

--

--