How to generate the SHA-1 hash for Android Google development

Sometimes we need to generate a SHA 1 hash for Playstore publishing or what not. This information can be explained with a single command at the Google documentation website at https://developers.google.com/android/guides/client-auth “Authenticating Your Client”. You’d’ think using the key tool command would be simple enough.

keytool -exportcert -list -v \
-alias <your-key-name> -keystore <path-to-production-keystore>

Well it is, if you modify the command… This is how my successful process looked when I wanted a debug SHA1 hash key when using Android Studio for Google development in Windows 10.

  1. Make sure you have your key store file (debug.keystore) which can be found at C:\Users\username.android\debug.keystore after a full Android Studio build.

Command to generate the debug SHA1 would be the one below.

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

You will then need to type a password. This password for debug Android Studio keystores are android. Type in android and there you have it! If you have problems starting the keystore program, you got it included with Android Studio so it should work, if not you have the keytool.exe program available at: C:\Program Files\Android\Android Studio\jre\bin

Firebase Angular can’t refresh without useHash setting to true

Are you familiar with the error page below (see bottom of this post)? Well, I was too. This problem can happen with Firebase when you don’t want to use the useHash (the hashtag # in the url) in your app routing module. I am using Angular 10.0.3 here. Now what could be the issue is that when you initialized Firebase within the project with firebase init, you might have chosen to set the redirect all pages option to no, and well, and that was the issue for me. To resolve this issue once and for all, go to your firebase.json file and add the rewrites part.

  "hosting": {
    "public": "dist",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }

If you are using something else rather than Firebase then you need to change your server settings where the mod rewrite executes. I would refer to this post on stackoverflow for more information which has information for some different servers: https://stackoverflow.com/posts/40833154/revisions

Error page below:

Page Not Found

This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.

Why am I seeing this?

You may have deployed the wrong directory for your application. Check your firebase.json and make sure the public directory is pointing to a directory that contains an index.html file.

You can also add a 404.html in the root of your site to replace this page with a custom error page.