0

I am developing an app with facebook auth. I have generated Hash Key for releasing the APK using below command.

 keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64

After setting Hash Key generated by above command, I tried to login with facebook with a release APK. But I could not login and every time get the invalid Hash key error.

Also, I have tried to generate Hash key using below code and it's working well with debug APK, not release APK.

try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String hashKey = new String(Base64.encode(md.digest(), 0));
            Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
        }
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "printHashKey()", e);
    } catch (Exception e) {
        Log.e(TAG, "printHashKey()", e);
    }

I can not get that what's the issue. I have already found this issue on the internet. But those solutions didn't work. So if anyone knows the solution, it will be appreciated.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Mahesh Vayak
  • 1,056
  • 12
  • 25

1 Answers1

1
  1. You need to add the release key in the Facebook developer console.
  2. Ensure that you've turned on the production mode for the app in Facebook dev. console.
Yash
  • 3,438
  • 2
  • 17
  • 33
  • Try to print the release key using Logcat. Check that it is same as that produced by terminal. If not, use the logcat key in the developer console. Also, check that you've enabled production mode for this app in Facebook console. – Yash Aug 08 '18 at 04:27
  • I have tried everything and using this command to generating hash key "keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64" and I got hash key but when I set this hash key in the developer console and after try login with release apk then I am getting Invalid hash key error. Set hash key production mode – Mahesh Vayak Aug 08 '18 at 04:29
  • I used to run into the same problem on some devices while trying to test the production app. I suggest you try login using a different device. Also, make sure that you've turned on the production mode. – Yash Aug 08 '18 at 04:31
  • I have tried login in the different device but got the same error. and also production mode on – Mahesh Vayak Aug 08 '18 at 04:33
  • Alright. I think the problem in your case can be of wrong keystore password. If you've not already released the app, you can try deleting the keystore and making a new one. If you enter wrong password while running the keystore command, you'll get wrong keys. – Yash Aug 08 '18 at 04:36
  • No, I am sure my keystore and password both are correct. – Mahesh Vayak Aug 08 '18 at 04:38
  • That is strange. Try rebuilding the release apk. – Yash Aug 08 '18 at 04:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/177603/discussion-between-mahesh-vayak-and-stupidly-logical). – Mahesh Vayak Aug 08 '18 at 04:41