Android Facebook SDK: generate release key hash

MikeKeepsOnShine picture MikeKeepsOnShine · Dec 12, 2014 · Viewed 76.1k times · Source

I'm building an app in which users can log in with Facebook.

I've created the hash keys like following:

try {
         PackageInfo info = getPackageManager().getPackageInfo(
         "com.app.package",
         PackageManager.GET_SIGNATURES);
         for (Signature signature : info.signatures) {
         MessageDigest md = MessageDigest.getInstance("SHA");
         md.update(signature.toByteArray());
         Log.d("KeyHash", "KeyHash:"+ Base64.encodeToString(md.digest(),
         Base64.DEFAULT));
         Toast.makeText(getApplicationContext(), Base64.encodeToString(md.digest(),
                 Base64.DEFAULT), Toast.LENGTH_LONG).show();
         }
         } catch (NameNotFoundException e) {

         } catch (NoSuchAlgorithmException e) {

         }

In debug mode, everything works well.

When I export the project for release, it gives this error:

"Invalid key hash. The key hash ****************** does not match any stored key hashes"

I paste the key printed in the Facebook Developer dashboard, but the application still gives me that error.

The complete package of my actvity is "com.app.package.views" and I tried to use this package (as Google Play Package Name) in the dashboard, but nothing changed.

How can I solve it? How can I generate the right release key hash?

Answer

Abhi picture Abhi · Apr 14, 2015

You followed the steps that facebook provides for the creation of a login application?

You need a 'Production keyhash' obtained starting your release keystore:

From comand line:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

And add this key on facebook app page options.

More information: https://developers.facebook.com/docs/android/getting-started/