编译后无效键散列APK,以及如何解决这一对许多设备?这一、如何解决、设备、键散列

2023-09-05 03:48:02 作者:小太阳哟

我建立了一个通过Facebook登陆按钮我的应用程序,它的正常工作的虚拟设备,但之后,我建我的应用程序APK和实际设备上进行测试,有一个问题无效的密钥散列该密钥散列lULhSMXXXXXXXXXX不匹配任何存储的密钥散列在 HTTP配置你的应用程序键哈希值​​://开发商。 facebook.com/apps/XXXXXXX 。 然后我去developers.facebook.com/apps/XXXXXXX并添加密钥散列lULhSMXXXXXXXXXXXX来设置,它的工作正常。所以,我有一个问题,如果我安装我在许多不同的设备上的应用程序,我该怎么做通过Facebook登陆无按钮的工作必须添加一个密钥散列为每个设备是这样的。谢谢。这是我的code

  @覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);

    loginButton =(LoginButton)findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList(电子邮件));

    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager,
            新FacebookCallback< LoginResult>(){
                @覆盖
                公共无效的onSuccess(LoginResult loginResult){
                    //应用code
                    loginFacebook(loginResult);
                }

                @覆盖
                公共无效OnCancel的(){
                    //应用code
                }

                @覆盖
                公共无效onerror的(FacebookException除外){
                    //应用code
                }
            });

私人无效loginFacebook(最终LoginResult loginResult){
    GraphRequest请求= GraphRequest.newMeRequest(
            loginResult.getAccessToken(),
            新GraphRequest.GraphJSONObjectCallback(){
                @覆盖
                公共无效onCompleted(的JSONObject对象,GraphResponse响应){

                    字符串userid = NULL;
                    字符串名称= NULL;
                    尝试 {
                        用户id = object.getString(ID);
                        名称= object.getString(姓名);
                    }赶上(JSONException E){
                        e.printStackTrace();
                    }



                    个人资料个人资料= Profile.getCurrentProfile();
                    Log.d(Shreks片段的onSuccess,+轮廓);

                    意图I =新的意图(LoginActivity.this,Intent.class);
                    startActivityForResult(ⅰ,0);
                    完();
                }
            });
    request.executeAsync();

}
 

解决方案

我们必须在Facebook的开发者加入共三个关键的哈希值。

在Android应用程序

1.使用软件包管理器。

 尝试{
                PackageInfo信息= getPackageManager()getPackageInfo(getPackageName(),PackageManager.GET_SIGNATURES)。
                对于(签名签名:info.signatures){
                    消息摘要MD = MessageDigest.getInstance(SHA);
                    md.update(signature.toByteArray());
                    字符串标志= Base64.en codeToString(md.digest(),Base64.DEFAULT);
                    Log.e(我的钥匙HASH:符号);
                    // textInstructionsOrLink =(TextView中)findViewById(R.id.textstring);
                    //textInstructionsOrLink.setText(sign);
                    Toast.makeText(getApplicationContext(),标志,Toast.LENGTH_LONG).show();
                }
            }赶上(PackageManager.NameNotFoundException E){
                Log.d(不,没了);
            }赶上(抛出:NoSuchAlgorithmException E){
            }
 
一键反编译apk

使用命令行2.Debug键

 密钥工具-exportcert -alias androiddebugkey -keystore C:\用户\用户名\ .android \ debug.keystore | C:\ OpenSSL的-0.9.8k_X64 \ BIN \ OpenSSL的SHA1 -binary | C:\ OpenSSL的-0.9.8k_X64 \ BIN \ OpenSSL的的base64
 

使用命令行3.Release键

 密钥工具-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
 

请加入这一切关键的哈希值,并再次检查。

注意

您必须产生相同的机,这是在所有这些键 通过使用密钥库签署APK。 我们要增加两个调试键哈希值,因为生产的重点由包 经理和命令行是不同的。

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, there is a problem "Invalid key hash. The key hash lULhSMXXXXXXXXXX does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/XXXXXXX. Then I go to developers.facebook.com/apps/XXXXXXX and add the key hash lULhSMXXXXXXXXXXXX to setting and it worked normally. So I have a question, if I install my app in many different devices, how can I make the "Log In with Facebook" button working without have to add a key hash for each device like this. Thank you. This is my code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions(Arrays.asList("email"));

    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    // App code
                    loginFacebook(loginResult);
                }

                @Override
                public void onCancel() {
                    // App code
                }

                @Override
                public void onError(FacebookException exception) {
                    // App code
                }
            });

private void loginFacebook(final LoginResult loginResult) {
    GraphRequest request = GraphRequest.newMeRequest(
            loginResult.getAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {

                    String userId = null;
                    String name = null;
                    try {
                        userId = object.getString("id");
                        name = object.getString("name");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }



                    Profile profile = Profile.getCurrentProfile();
                    Log.d("Shreks Fragment onSuccess", "" + profile);

                    Intent i = new Intent(LoginActivity.this, Intent.class);
                    startActivityForResult(i, 0);
                    finish();
                }
            });
    request.executeAsync();

}

解决方案

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 :

You have to generate all these keys on the same machine which is used to sign an APK using key store. We have to add two debug key hashes because key produced by package manager and command line are different.

 
精彩推荐
图片推荐