2

I'm using the Facebook login integration to my app. I configured hash key Facebook for signed APK and run successfully. But sometimes when i release a new APK file, the hash key is not valid any more ("invalid key hash facebook android does not match any stored").

I read this link below, found that "Also, depending on the PC, sometimes the key can change and if so, the hash changes and you'll have to just accommodate for that" android hash key

Could you please hep me to explain more detail about this? Is the hash key Facebook for signed APK sometimes changed? how about when the app is uploaded to play store?

Thanks so much.

Community
  • 1
  • 1
Dinh Thang
  • 31
  • 3
  • i faced same issue,after i got hash key while debug sign apk.that key worked for me. – Vasant Aug 01 '16 at 04:48
  • You need to register your hash key at facebook developer console while releasing your apk in release mode ! – Piyush Aug 01 '16 at 04:50
  • in facebook app settings page there is an option to add multiple hash values...if you are using android studio you can easily get hash value for signed build by running "signingReport" task directly from gradle task list at the right side window...thanks – Jayakrishnan Aug 01 '16 at 04:53

3 Answers3

0

The Debug Key Hash changes when switch your PC, because each PC has different debug.keystore files. When you take release keyhash using your release.keystore file it wont change even if you switch PC. In this case you are using the same release.keystore file.

LvN
  • 641
  • 1
  • 5
  • 21
  • With your comment, that's mean the hash key is never changed if we are using only one file release.keystore, isn't it? – Dinh Thang Aug 01 '16 at 05:09
  • Yeah.. It won't change as per facebook's developer documentation. – LvN Aug 01 '16 at 05:23
  • If it is changing make sure that you are using the same file and the keyhash you added to the facebook developer console is correct. I suggest you to take keyhash using logcat, don't go to the command line tool as it is confusing. You can use the @user3793589's answer. Generate the signed apk and run it on your device, check out the logcat and get your release keyhash. – LvN Aug 01 '16 at 05:31
0

Whenever your app is under development debug hash key is used for facebook Integration. The debug hash key is machine specific(i.e the PC in which you are working on)

Whereas the release hash key is different, as compared to debug key(It won't change). When you generate a signed apk for upload, a release hash key must be updated for Facebook Integration with your app.

Read this for better understanding on how to create a release hash key for facebook

You can check your key hash by using the following code:

    // Add code to print out the key hash
    try {
        String PACKAGE_NAME=getApplicationContext().getPackageName();;
        PackageInfo info = getPackageManager().getPackageInfo(
                PACKAGE_NAME, 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }       
Arshak
  • 2,799
  • 1
  • 23
  • 30
  • Thanks for your response. As i noted, i run successfully with hash key for Facebook with signed APK, but sometime when i generate a new APK file for testing, the hash key is not valid any more. I used only one the PC for that. With your comment, that's mean the hash key can be changed when we generate a new APK file, is it right? – Dinh Thang Aug 01 '16 at 04:57
  • @DinhThang Did you change your package name? or project name? – Arshak Aug 01 '16 at 05:00
  • @DinhThang I have added code, which will show your keyhash in logcat while running your app. You could compare that with the keyhash stored in facebook developer console & add the keyhash if it differs. – Arshak Aug 01 '16 at 05:08
  • @DinhThang Did you try comparing the Key hash received from logcat & the one's saved in the facebook developer console? – Arshak Aug 01 '16 at 05:13
  • Thanks Arshak. Sorry for my question is not clear. I know the way to get the hash key. My concern here is the hash key worked with APK file but sometime it is not valid though i generate APK file on the same machine which caused the build get the error with Facebook login function. – Dinh Thang Aug 01 '16 at 05:17
  • The error is the mismatch the Key hash "invalid key hash facebook android does not match any stored" – Dinh Thang Aug 01 '16 at 05:22
  • @DinhThang Try these solutions: [link1](http://stackoverflow.com/a/31725233/5744335) , [link 2](http://stackoverflow.com/a/27290250/5744335), [link 3](http://stackoverflow.com/a/20304015/5744335) – Arshak Aug 01 '16 at 05:26
0

You need to register both a developer hashkey (related to your computer) and the production hashkey (related to the signed version) on facebook. To make sure you are having the right key, run this in your code and copy the output :

try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "Your package name", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            System.out.println(Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
user3793589
  • 408
  • 3
  • 14