Invalid key hash after build to apk and how to solve this for many device?

后端 未结 1 584
面向向阳花
面向向阳花 2020-12-18 16:18

I have built a \"Log In with Facebook\" button for my app, it\'s working normally in the virtual device, but after I built my app to apk and test it on the real device, ther

相关标签:
1条回答
  • 2020-12-18 16:24

    We have to add total three key hashes at Facebook developer.

    1.using package manager in android app.

      try {
                    PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
                    for (Signature signature : info.signatures) {
                        MessageDigest md = MessageDigest.getInstance("SHA");
                        md.update(signature.toByteArray());
                        String sign = Base64.encodeToString(md.digest(), Base64.DEFAULT);
                        Log.e("MY KEY HASH:", sign);
                        //textInstructionsOrLink = (TextView)findViewById(R.id.textstring);
                        //textInstructionsOrLink.setText(sign);
                        Toast.makeText(getApplicationContext(), sign, Toast.LENGTH_LONG).show();
                    }
                } catch (PackageManager.NameNotFoundException e) {
                    Log.d("nope", "nope");
                } catch (NoSuchAlgorithmException e) {
                }
    

    2.Debug key using command line

    keytool -exportcert -alias androiddebugkey -keystore C:\Users\username\.android\debug.keystore | C:\openssl-0.9.8k_X64\bin\openssl sha1 -binary | C:\openssl-0.9.8k_X64\bin\openssl base64
    

    3.Release key using command line

    keytool -exportcert -alias app_alias -keystore C:\Users\usename\app_keysrore.jks | C:\openssl-0.9.8k_X64\bin\openssl sha1 -binary | C:\openssl-0.9.8k_X64\bin\openssl base64
    

    please add this all key hashes and check again.

    Note :

    1. You have to generate all these keys on the same machine which is used to sign an APK using key store.
    2. We have to add two debug key hashes because key produced by package manager and command line are different.
    0 讨论(0)
提交回复
热议问题