Facebook Key Hash Issues on Android

The invalid key hash error shows up when you're trying to run your Android app with Facebook Login and it just refuses to authenticate. Facebook sees the debug key doesn't match what's registered in your developer console, and you get stuck. I've dealt with this more times than I'd like to count, usually at 11pm before a demo.

Unlock Your Facebook Fixing Invalid Key Hash On Android In 5 Easy Steps

Step 1: Generate your debug key hash. Open your terminal and run this command. Make sure you're pointing to the right keystore path and using the correct alias. keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 The password is android. Always android. If you use a different keystore for release builds, you'll need the hash from that one too.

Step 2: Copy the output. It looks like a long string of random characters. Copy it exactly. Don't add spaces. Don't trim it. Step 3: Go to your Facebook Developer Console. Navigate to your app settings, find the Facebook Login section, then look for the Android platform settings. Paste your hash into the Key Hashes field. Step 4: Save and test. Rebuild your app and run it. If you get the same error, check that you're actually using the debug.keystore and not some other keystore file you created accidentally.

Step 5: Handle multiple hashes. Most projects end up needing two hashes, one for debug and one for release. Paste both into the Key Hashes field separated by a space, or add them individually if your console version supports it. Here's something most guides don't mention. If you're using Android Studio on a Mac and your home directory has special characters in it, the ~/.android path can resolve incorrectly. I spent two hours debugging this once. The fix was to use the full absolute path instead of the tilde shorthand. Another edge case that bites people regularly. The hash you generate depends entirely on which keystore you're signing with. If you switched from an older version of Android Studio, you might have multiple .keystore files floating around. Run this command to see which debug keystore your current install is actually using:

Get the Full Details

android - Invalid key hash in facebook login - Stack Overflow
android - Invalid key hash in facebook login - Stack Overflow

find ~/.android -name debug.keystore Sometimes the output shows multiple results. Use the hash from the one in your default ~/.android folder, not some old copy you made and forgot about. This whole process usually takes about 5 to 10 minutes if everything goes smoothly. The frustrating part isn't the steps themselves. It's the times when the hash works locally but fails on a different machine, or when your CI/CD pipeline uses a different signing key than your local build. In those cases you need to add the build machine's hash too, or configure your pipeline to use the same keystore.

If you're building for production, you also need the release key hash. Generate it the same way but point to your release keystore instead of the debug one. Don't skip this. The app will work in debug but crash in production if you haven't added the release hash. The key takeaway is just to keep your hashes organized. I keep a text file with all my project hashes labeled by app and environment. Saves you from going back through this process every time you start a new project.