1

I am using Facebook login sdk for login into my app. While it working in emulator and also works with build apk on mobile with Facebook app and without app.

But when i publish app into play store then its not working. I disable or uninstall Facebook app then it works else it doesn't work.

I also change my Key Hashes with signed jks file(I have .jks file instead of .keystore). but it doesn't work.

Any idea whats wrong with it.

I download release app form play store.

Vivek
  • 449
  • 18
  • 36

2 Answers2

3

Finally, I resolved the issue.

Reason Behind this issue While publishing an App to play store, I did APP SIGNING from Google Play, hence new SHA-1 key was created there. To see this key, go to Google Play Console, select your app, then Release Management -> App Signing On this page, I got new SHA-1 key under section "App signing certificate "

Facebook developer account, we need to add Key hashes generated by our keystore. But in this case, we also need to add Key hash corresponds to this APP SIGNING certificate. Now the question is, how to get key hash for this certificate/SHA-1 fingerprint?

How to create Key Hash from SHA-1 key of Google Play APP SIGNING?

To generate key hash from SHA-1 key, execute a small Command,

echo SHA1_here | xxd -r -p | openssl base64

And You can also use online Converter: https://hash.online-convert.com/sha1-generator

I have generated key hash by using keytool, openssl:-

keytool -exportcert -alias "Aliasname" -keystore "Path to keystore(jks)" |openssl sha1 -binary | openssl base64

Copy this key hash and paste it to Facebook Developer account settings for your app. This is how my problem got solved.

Thanks all developers for comments. :)

Jaspalsinh Gohil
  • 941
  • 1
  • 9
  • 20
2

Try using this code:

 public void Get_hash_key() {
    PackageInfo info;
    try {
        info = getPackageManager().getPackageInfo("com.your_packaage_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 (PackageManager.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());
    }
}

call this method in onCreate() with your package name replaced..it will print the hash key..

copy the key and add it to the developer panel. Under App name

EDIT in your Build.gradle

 release {
        minifyEnabled false
        debuggable true   //add this
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

after building the release apk run it on phone and you will be able to see any logcat error regarding the facebook sdk.

Also remember to debuggable false when uploading it to play store.

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • i tried my package name which is `in.unfurl.activity` is says expression expected...what to do...should i write in string??? – Vivek Apr 18 '17 at 08:44
  • it says `E/name not found: android.content.pm.PackageManager$NameNotFoundException: in.unfurl.activity` – Vivek Apr 18 '17 at 08:53
  • my package name is `package in.unfurl.activity;` – Vivek Apr 18 '17 at 08:54
  • just add `in.unfurl.activity` like: `info = getPackageManager().getPackageInfo("in.unfurl.activity", PackageManager.GET_SIGNATURES);`..also check if it the right package name..cause this exception is thrown when...https://developer.android.com/reference/android/content/pm/PackageManager.NameNotFoundException.html – rafsanahmad007 Apr 18 '17 at 08:57
  • i got hash key....is it for **release** app code or **build** app and i already upload app to play store. is this work with uploaded apk. – Vivek Apr 18 '17 at 09:10
  • it is for release hask key..and it will work for the uploaded apk also if you do not change the package name... – rafsanahmad007 Apr 18 '17 at 09:11
  • did u copy the full key hash including `=`? – rafsanahmad007 Apr 18 '17 at 09:21
  • i think it's your setup problem ...i edited the answer...also did you add privacy policy URL in panel..? it's required – rafsanahmad007 Apr 18 '17 at 09:27
  • i am already using this ` buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }` – Vivek Apr 18 '17 at 09:31
  • just add `debuggable true` – Vivek Apr 18 '17 at 09:36
  • @Vivek it's not for working..`debuggable true` is for showing any error related to facebook login..debug will help you get a clear picture of the problem/error.. – rafsanahmad007 Apr 18 '17 at 11:16
  • i think problem is hash key is not properly set..... i got 5 diffent hash key with different method....some are thround cmd – Vivek Apr 18 '17 at 11:21
  • and i can not build release app when `shrinkResources true` – Vivek Apr 18 '17 at 11:22
  • `omit` ? how can i do this – Vivek Apr 18 '17 at 11:25
  • i mean remove it...you do not need that..i also suggest create a new app id and add it to manifest ..see it it works.. – rafsanahmad007 Apr 18 '17 at 11:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/141967/discussion-between-rafsanahmad007-and-vivek). – rafsanahmad007 Apr 18 '17 at 11:28