Question

I am working on a Cordova project which integrates the Facebook SDK.

I am using Cordova 2.9 and the Android Facebook SDK 3.5.2.

I created my own keystore via the Android SDK version of Eclipse and have been using this successfully to provide release builds to the client.

The Facebook application has SSO enabled for Android, is available publicly and I have also generated my hash and included it in the relevant settings section.

All has been working fine until today.

My client has supplied me with their own keystore to sign and build APKs to release to them.

I use Eclipse to export the Android project and select their newly supplied keystore. The application exports successfully and I am able to push it to my test device.

Now, when I try to log in via Facebook, you can't enter the app via any other route, the Facebook login dialogue appears, I enter my credentials but I receive a Facebook error stating that the key I have provided does not match any allowed key.

The key that is displayed is not one that I recognise as I use the same machine for development all the time and have previously generated my key hash using the technique described here in Section 4:

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

Can I use the client supplied key to sign and release their application?

Why is there an unknown hash being reported in the error message now I have started using the client's key store?

Any ideas would be gratefully appreciated.

Was it helpful?

Solution

I think the issue is not adding the hash of your new signing key to the Facebook console. I believe you have done that for your debug key that is auto-generated by Eclipse as given in the Facebook getting started guide. Just generate the key hash for the new keystore, i.e. your client's keystore.

keytool -exportcert -alias yourkey -keystore path_to_your_new_keystore | openssl sha1 -binary | openssl base64

Then add the hash to Facebook console in the android supported key hashes section. Hope this helps resolve your issue!

UPDATE For an alternative approach(read => bit cumbersome), follow the below steps

1.Use the below code in your main activity or application.

// DO NOT FORGET TO REMOVE
PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String something = new String(Base64.encode(md.digest(), 0));
        //String something = new String(Base64.encodeBytes(md.digest()));
        Log.e("hash key", something);
    }
} catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());
}
// DO NOT FORGET TO REMOVE

Code taken from - https://stackoverflow.com/a/9600642/1304559

2.Export the project as a signed apk. Choose your new keystore and alias

3.Install the apk onto a device

4.Wait for the log message to appear, copy the key hash from logcat console.

5.Add another key hash in your Facebook web dashboard under Android key hash section

6.Remove the above code, generate the signed apk again. Try it on a device and access facebook login

This alternate method should definitely work. Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top