Facebook SDK v4.2.4 - Android - Login not working

Hi Guys,

I’ve been stuck on this one for most of the day.

I’m trying to run the example scene that comes with the Facebook SDK v4.2.4 unity package. I have it working fine on iOS except Android is giving me trouble.

When I launch the application I press FB.Init and it loads successfully. When I press the Login button the screen goes black for less than a second and returns back to the scene and the other buttons (except Publish Install) are still greyed out.

I believe my problem is related to my Key Hash. At first my key has wasn’t appearing in the FacebookSettings panel in Unity. So I downloaded an OpenSSL zip and moved it into my jdk bin folder (C:\Program Files\Java\jdk1.7.0_40\bin\openssl.exe) I then manually got a key from the cmd. Then I noticed at a later point the FacebookSettings panel was showing me the same key hash I got from the cmd.

Maybe I stuffed up retrieving the correct key hash?

What was the correct way to retrieve my key hash?

Currently my Facebook app settings match the details in Unity. (package name, class name, key hash). I am doing all of my Android testing on a device and not an emulator.

Apologies for writing another “Login not working” question. I read through the other questions and felt they all had different issues to mine as they were able to see the login screen.


#Note, if you’re on a Mac…
.

the “Rafael solution” is the only solution:

(it is also (by far) the easiest and simplest solution if you are not on a Mac)

Hey no worries. Android development is tough. As one of the engineers that built the SDK, we’re trying to make it easier for people. It sounds like you already did this:

Are you using the default package name: com.Company.ProductName ? There’s a known issue that somethings don’t work correctly with that. You can edit the Android build settings to change the Bundle Identifier (we called it “Package Name” here to match the facebook developer settings). We’ll also look into it on our end.

Some other answers that might help us if the above doesn’t help:
-Which version of Android do you have?
-Is the Facebook App installed?
-Do you have adb setup to monitor the logs from Android? A log dump of adb log right before and after the login happened would help. (Set your unity build to do a “Development Build” for more debug stuff to log.)

You can send all that info to: unity-sdk@fb.com and we’ll follow up.

UPDATE: We found out that sometimes the older version of openssl may not generate the correct keyhash. You can either update your openssl or check out this stackoverflow answer here for an alternate solution to getting a proper keyhash:

I was having same problem, I tried a lot of things like changing openssl or generating release keystore properly, and many other stuffs but what really solved my problem is, my game is in ‘landscape’ mode and com.facebook.LoginActivity was in ‘portrait’ mode. I manually changed it to ‘landscape’ in AndroidManifest.xml located inside Assets\Plugins\Android folder which solved the problem for me.
Hope that helps.
alt text

The Best and the easiest solution ever!!!

I have done a tricky way to achieve that which is more simpler than any solution.

  1. Let your game app stay with the generated key hash in facebook edit setting. Don’t worry about the correct key hash.
  2. Make sure you have wrong android hash key pasted on facebook app setting in your developer account.
  3. Build your game and try log in with your Fb developer account.
  4. Now As soon as your game app doesn’t find the same hash key then facebook app will pop up and taaaddaaaaaa. Here you go with correct key hash, just note down the hash key and now paste into your facebook app setting in your developer account

Worked like a charm!!!

I’ve experienced the same problem. Just upgrade your facebook sdk to 4.3.6 and everything will be okay :slight_smile:

I had the same problem. It worked once I uninstalled the Facebook App from my device. I checked it by displaying the FB.UserId,FB.AccessToken - which were no more empty strings!

Mine also only works when I uninstall the Facebook App from my device. Is there a fix for this yet? There’s so many apps that have facebook integration. I would think it would have to be fixed by now. Any remedies?

Re-posting here to help anyone else with this problem…

I found the actual reason for the different keystore value. It is using the keystore defined in your publish settings. You have to either define the debug.keystore file there or use something like the fix i wrote for the faceboook sdk below.

Facebook SDK Fix

I just make the facebook sdk use the defined PlayerSettings.Android keystore values. Hope this helps! Cheers! (Just update to 6.0)

Did this get solved yet? I’m in the same boat and there is no way any real enduser will uninstall facebook to do anything.

For me, x64 Windows 7/8 user, the solution was download the last and official OpenSSL for windows at Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

It’s important to download the non light version and if you are asked during installation download also the Visual C++ 2008 Redistributables.

Also during installation, choose to add the bin folder at OpenSSL/bin and add this folder to your system Path environment variable.

To verify if you have the correct hash key, open the cmd and type:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

password: android

(if you are not prompted for a password, something is wrong and you must ensure the debug.keystore is present at Users/[user]/.android/)

If the resulted key hash is equal to the Unity > FacebookSettings > Debug Android Key Hash, then copy and paste these into your “Native Android App” Settings on Log into Facebook and you are good to go!

Cheers

random question: What is “Publish Install” Even for? lol

Simple and awesome solution for getting correct key hash is as below.

just replace line number 70 in FacebookAndroidUtil.cs with
var arguments = @“”“keytool -storepass {0} -keypass {1} -exportcert -alias {2} -keystore {3} | openssl md5 -binary | openssl base64"”";

this will give correct key hash. and it is working fine on both windows or mac.