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)
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.)
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.
I have done a tricky way to achieve that which is more simpler than any solution.
Let your game app stay with the generated key hash in facebook edit setting. Don’t worry about the correct key hash.
Make sure you have wrong android hash key pasted on facebook app setting in your developer account.
Build your game and try log in with your Fb developer account.
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
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.
(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!