When integrating Facebook Login into an Android application, one of the most important configuration steps is generating and registering the correct Android Key Hash in the Meta Developer Console.
Whether you're developing an Android application using Java, Kotlin, Flutter, or React Native, Facebook Login may fail if your application's key hash is missing or incorrect.
In this comprehensive tutorial, you'll learn how to generate Android key hashes using different methods, configure them in your Facebook app, troubleshoot common errors, and prepare your application for production.
What Is an Android Key Hash for Facebook?
An Android Key Hash is a Base64-encoded SHA-1 digest of the certificate used to sign your Android application.
Meta uses the registered key hashes as part of its Android Facebook Login configuration to recognize application signing certificates.
Android applications can have different signing certificates depending on how they are built and distributed.
Debug Key Hash: Used during local development and testing.
Release Key Hash: Used for release builds signed with your production certificate.
Google Play App Signing Key Hash: Required when Google Play signs the APKs delivered to users with a different certificate.
Important: The Facebook Android Key Hash is not the same as the SHA-1 fingerprint shown in Firebase or Google Cloud Console. Facebook requires the Base64-encoded representation of the certificate's SHA-1 digest.
Prerequisites
Before getting started, make sure you have the following:
Android Studio or an Android development environment.
Java Development Kit (JDK) installed.
OpenSSL installed, if using the command-line method.
An Android application project.
Access to a Meta Developer account.
Your application's package name and signing configuration.
Method 1: Generate the Debug Key Hash Using Keytool and OpenSSL
This is one of the most commonly used methods for generating a Facebook Android Key Hash.
Step 1: Locate Your Android Debug Keystore
Android Studio normally creates a debug keystore automatically.
Default locations:
Windows
C:\Users\YOUR_USERNAME\.android\debug.keystore
Linux
/home/YOUR_USERNAME/.android/debug.keystore
macOS
/Users/YOUR_USERNAME/.android/debug.keystore
The default debug keystore normally uses:
Property | Default value |
|---|---|
Keystore filename |
|
Key alias |
|
Keystore password |
|
Key password |
|
These are the standard Android debug signing credentials, not your production credentials.
Step 2: Open Terminal or Command Prompt
On Linux or macOS, open Terminal.
On Windows, open PowerShell, Command Prompt, or Git Bash with the necessary tools available in your PATH.
Step 3: Execute the Key Hash Command
Linux
keytool -exportcert \
-alias androiddebugkey \
-keystore "$HOME/.android/debug.keystore" \
-storepass android \
| openssl sha1 -binary \
| openssl base64 -A
macOS
keytool -exportcert \
-alias androiddebugkey \
-keystore "$HOME/.android/debug.keystore" \
-storepass android \
| openssl sha1 -binary \
| openssl base64 -A
Windows (Git Bash)
keytool -exportcert \
-alias androiddebugkey \
-keystore "$USERPROFILE/.android/debug.keystore" \
-storepass android \
| openssl sha1 -binary \
| openssl base64 -A
For Git Bash, you may need to use $HOME/.android/debug.keystore instead, depending on where Android Studio created the keystore.
Step 4: Copy the Generated Key Hash
Example output:
AbCdEfGhIjKlMnOpQrStUvWxYz0=
Illustrative output only. Your actual key hash will be different.
Copy the entire output, including the trailing = character when present.
You'll use this value when configuring your Facebook application.
Method 2: Generate the Key Hash Using Java or Kotlin
If you don't want to use OpenSSL, you can generate the key hash programmatically inside your Android application.
This method is particularly useful when diagnosing Facebook Login configuration problems.
Step 1: Open Your Android Project
Open Android Studio and navigate to your application's MainActivity or another suitable debugging component.
Step 2: Add the Required Imports
For a Java project:
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Build;
import android.util.Base64;
import android.util.Log;
import java.security.MessageDigest;
Step 3: Add the Key Hash Generation Code
private void printFacebookKeyHash() {
try {
PackageManager pm = getPackageManager();
Signature[] signatures;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
PackageInfo info = pm.getPackageInfo(
getPackageName(),
PackageManager.GET_SIGNING_CERTIFICATES
);
signatures = info.signingInfo
.getApkContentsSigners();
} else {
PackageInfo info = pm.getPackageInfo(
getPackageName(),
PackageManager.GET_SIGNATURES
);
signatures = info.signatures;
}
for (Signature signature : signatures) {
MessageDigest md =
MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String keyHash = Base64.encodeToString(
md.digest(),
Base64.NO_WRAP
);
Log.d("FacebookKeyHash", keyHash);
}
} catch (Exception e) {
Log.e(
"FacebookKeyHash",
"Unable to generate key hash",
e
);
}
}
This example is intended for debugging and uses Android signing APIs compatible with older and newer Android versions. In production code, handle nullable signing information and certificate rotation as appropriate.
Step 4: Call the Method
Inside onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
printFacebookKeyHash();
}
Step 5: Run the Application
Connect an Android device or launch an emulator.
Run your application.
Open Android Studio Logcat.
Search for
FacebookKeyHash.
Example:
D/FacebookKeyHash: AbCdEfGhIjKlMnOpQrStUvWxYz0=
Copy the generated hash and add it to your Meta Developer Console.
Note: This method retrieves the signing certificate of the application currently installed on the device. Therefore, a debug build generates the debug signing key hash, while a release build generates the hash of its actual signing certificate.
Method 3: Generate a Release Key Hash
Before publishing your application, you must register the hash associated with the certificate that signs your release application.
Step 1: Locate Your Release Keystore
Your release keystore might be named:
release-key.jks
or:
myapp-release.keystore
Keep your release keystore and passwords secure. Never upload them to public repositories.
Step 2: Run the Release Key Hash Command
keytool -exportcert \
-alias YOUR_RELEASE_ALIAS \
-keystore /path/to/release-key.jks \
| openssl sha1 -binary \
| openssl base64 -A
Replace YOUR_RELEASE_ALIAS with your actual key alias and update the keystore path.
The command will request your keystore password.
Step 3: Save the Output
Example:
XyZaBcDeFgHiJkLmNoPqRsTuVw0=
This represents your release certificate's Facebook Key Hash.
Do not replace the debug hash with the release hash. Register both hashes if you need Facebook Login to work in development and release builds.
Method 4: Get the Key Hash From Google Play App Signing
If your application uses Google Play App Signing, Google may sign the APKs distributed to users with a different certificate than the one you use to upload your application.
Therefore, the release keystore hash generated locally might not match the signing certificate of the installed Play Store version.
Step 1: Open Google Play Console
Visit Google Play Console and select your application.
Step 2: Navigate to App Signing
Open the App integrity section and locate the App signing key certificate details.
The exact navigation labels may vary as Google updates the Play Console.
Step 3: Download the Certificate
Download the public app signing certificate, typically provided as a .der file.
Step 4: Generate the Facebook Key Hash
Run:
openssl dgst -sha1 -binary deployment_cert.der \
| openssl base64 -A
Replace deployment_cert.der with your downloaded certificate filename.
Step 5: Add the Generated Hash to Meta
Copy the output and register it alongside your debug and other required signing key hashes.
You can also generate the same value from the SHA-1 fingerprint displayed in Play Console by converting its hexadecimal bytes to Base64. Do not simply paste the hexadecimal SHA-1 fingerprint into Meta's Key Hashes field.
Method 5: Generate the Key Hash Using Gradle Signing Report
Android Gradle provides a signing report that displays signing certificate fingerprints.
Step 1: Open Android Studio Terminal
Navigate to the root directory of your Android project.
Step 2: Execute the Signing Report
On Linux or macOS:
./gradlew signingReport
On Windows:
.\gradlew.bat signingReport
Step 3: Find the SHA-1 Fingerprint
Example output:
Variant: debug
Config: debug
Store: /home/user/.android/debug.keystore
Alias: AndroidDebugKey
SHA1: AA:BB:CC:DD:EE:FF:...
Step 4: Convert SHA-1 to Facebook Key Hash
The signing report provides a hexadecimal SHA-1 fingerprint, not the Facebook Key Hash itself.
Use Python to convert the full fingerprint:
import base64
sha1 = "AA:BB:CC:DD:EE:FF:..." # Full SHA-1 fingerprint
sha1_bytes = bytes.fromhex(
sha1.replace(":", "")
)
facebook_hash = base64.b64encode(
sha1_bytes
).decode("ascii")
print(facebook_hash)
Replace the placeholder with the complete SHA-1 fingerprint (20 bytes, or 40 hexadecimal characters).
How to Add the Android Key Hash to Your Facebook App
After generating your key hashes, configure your application in the Meta Developer Console.
Step 1: Open Meta for Developers
Visit Meta for Developers and select your Facebook application.
Step 3: Enter Your Android Package Name
For example:
com.example.myandroidappUse the actual applicationId of your Android app, not necessarily the package name declared in your source files.
Step 4: Enter Your Main Activity
Example:
com.example.myandroidapp.MainActivityUse the fully qualified activity name configured for your application.
Step 5: Add Your Key Hashes
Locate the Key Hashes field and enter your generated values.
For example:
Debug Key Hash:
AbCdEfGhIjKlMnOpQrStUvWxYz0=
Release Key Hash:
XyZaBcDeFgHiJkLmNoPqRsTuVw0=Add each actual key hash as a separate entry.
Step 6: Save Your Changes
Save the application configuration. Ensure the appropriate Facebook Login permissions, use case, and app access settings are configured for your intended users.
Common Facebook Android Key Hash Errors and Solutions
Error 1: Invalid Key Hash
A common Facebook Login error is:
Invalid key hash.
The key hash does not match any stored key hashes.Solution:
Check that you copied the complete Base64 value.
Confirm which certificate signed the installed app.
Register both debug and production hashes when needed.
Verify that the hash is registered under the correct Meta app.
Error 2: Facebook Login Works in Debug but Fails in Release
Cause: The debug and release signing certificates are different.
Solution: Generate the release key hash and add it to your Facebook application configuration.
Error 3: Facebook Login Works Locally but Fails After Publishing to Google Play
Cause: Google Play App Signing may use a different signing certificate.
Solution: Generate the hash from the Google Play app signing certificate and register it in Meta.
Error 4: Keytool Command Not Found
Example:
keytool: command not foundSolution: Install a JDK and ensure its bin directory is included in your system PATH.
Verify:
keytool -helpError 5: OpenSSL Command Not Found
Example:
openssl: command not foundSolution: Install OpenSSL and ensure the executable is accessible from your terminal.
On Ubuntu:
sudo apt update
sudo apt install opensslOn macOS, OpenSSL or a compatible command-line implementation may already be available.
Error 6: Keystore File Does Not Exist
Example:
Keystore file does not existSolution: Verify the keystore location. If you have never built the Android project, run a debug build to allow the Android build tools to create a debug keystore.
Do not delete an existing production keystore just to resolve this error.
Debug vs. Release vs. Google Play Key Hash
Key hash type | When to use |
|---|---|
Debug | Local development and testing |
Release | Locally signed release builds |
Google Play App Signing | Apps distributed through Google Play |
CI/CD signing certificate | Builds signed with a distinct CI/CD certificate |
You may need to register multiple hashes depending on your build and distribution workflow.
Best Practices for Managing Facebook Android Key Hashes
Register all signing certificate hashes required by your development, testing, and production environments.
Store production signing keys securely and never commit private keystores or passwords to Git.
Verify the actual installed application's signing certificate when debugging.
Keep your Meta App ID and Android package configuration consistent.
Test Facebook Login on a real device and on the Google Play-distributed build before launch.
Update Meta configuration when your app's signing certificate changes.
Frequently Asked Questions
1. Is the Facebook Android Key Hash the same as the SHA-1 fingerprint?
No. The Facebook Key Hash is the Base64 encoding of the SHA-1 digest of the signing certificate. A standard SHA-1 fingerprint is usually represented as colon-separated hexadecimal bytes.
2. Can I use the same key hash for multiple Android applications?
Technically, applications signed with the same certificate can have the same certificate-derived key hash. However, each application's package name and Meta configuration must still be correct.
3. Do I need a separate key hash for Flutter or React Native?
No. Flutter and React Native Android applications use Android signing certificates just like native Android applications. The same generation methods apply.
4. Can I add multiple key hashes to a Facebook application?
Yes. This is commonly necessary to support debug, release, and Google Play signing certificates.
5. Is the Facebook Android Key Hash a secret?
No. It is derived from the public signing certificate. However, the private signing key, keystore credentials, and other sensitive application secrets must remain protected.
6. Does changing the application package name change the key hash?
Not by itself. The key hash is derived from the signing certificate, not the package name. You must still update the package configuration in Meta.
Conclusion
Generating the correct Android Key Hash is an essential part of configuring Facebook Login for Android applications.
The most convenient method for local development is using keytool and OpenSSL. For production applications, you should also register the release signing certificate hash and, when applicable, the Google Play App Signing certificate hash.
By following these steps, you can avoid common Facebook Login errors and ensure your Android application is configured correctly across development and production environments.


