Facebook for Android application with release key

I am trying to release my application on Google Play. I have a Facebook login in my application. Until yesterday, everything worked fine until I started the application with debug.keystore. But when I use my own release key and sign my application, Facebook is not logged in, and I cannot understand why.

Following this link and did everything that was a meter: like this: key-hash-for-android-facebook-app

I changed the machines, I changed the platforms (windows and mac osx ML) to get a solution, but the same problem. THIS IS NOT INCLUDED. The code below gives me the correct hash key when I use debug.keystore, where when I sign the application even with different keys, I get the same Hashkey (which I came to after many tests that the key I get is wrong)

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());
}

So, are there any additional steps that we need to take when signing the application using the release key. Please, help.

+2
source share
5 answers

Here is what I did to solve the problem:

  • Used by openssl-0.9.8e_WIN32 Instead of openssl-0.9.8k_WIN32
  • , , , - .

:

keytool -exportcert -alias <aliasNameUseInReleaseKeystore> -keystore <ReleasekeystoreFilePath> | openssl sha1 -binary | openssl base64

P.S. , , . .

+8

.

1. :

keytool -exportcert -alias androiddebugkey -keystore c:\Users\YourUser\.android\debug.keystore | openssl sha1 -binary | openssl base64

:

keytool -exportcert -alias "yourAliasUsedWhenYouGeneratedTheKey" -keystore "C:\Users\YourUser\AppData\Local\Android\android-studio\key.jks" | openssl sha1 -binary | openssl base64

2. Facebook , " " " ()". - ().

3. strings.xml :

<string name="app_id">123456789</string>
<string name="app_id_debug">987654321</string>

4. , , appid Facebook :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);

    String appId;

    try {
        ApplicationInfo appinfo = getActivity().getPackageManager().getApplicationInfo(getActivity().getPackageName(), 0);
        boolean isDebugMode = (0 != (appinfo.flags &= ApplicationInfo.FLAG_DEBUGGABLE));

        if (isDebugMode)
            appId = getString(R.string.app_id_debug);
        else
            appId = getString(R.string.app_id);
    } catch (PackageManager.NameNotFoundException e) {
        appId = getString(R.string.app_id);
    }

    Session session = new Session.Builder(getActivity().getBaseContext()).setApplicationId(appId).build();
    Session.setActiveSession(session);

    return inflater.inflate(R.layout.fragment_facebook_login, container, false);
}

, !!

+7

Linux

:

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

debug.keystore ".android",

Build

keytool -exportcert -alias <aliasNameUseInReleseKeystore> -keystore <RelesekeystoreFilePath> | openssl sha1 -binary | openssl base64

. , . , , - .

+5
source

Here is what I did to solve the problem:

Used by openssl-0.9.8e_WIN64 instead of openssl-0.9.8k_WIN64

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | PATH_TO_OPENSSL_LIBRARY\bin\openssl sha1 -binary | PATH_TO_OPENSSL_LIBRARY\bin\openssl base64

use your storage cache alias as RELEASE_KEY_ALIAS and its saved path with the file name as RELEASE_KEY_PATH.

Note. Use your keystore password if you request a type password.

+1
source

Try this code below in the create method

 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());
            Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));//will give developer key hash
            Toast.makeText(getApplicationContext(),Base64.encodeToString(md.digest(), Base64.DEFAULT), Toast.LENGTH_LONG).show(); //will give app key hash or release key hash

            }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
0
source

Source: https://habr.com/ru/post/1660325/


All Articles