1
votes

The problem

The first time I call FB.Login I'm redirected to facebook but then there seems to be a problem with coming back to my app. I'm getting the message "[App name] has stopped working." I've posted a screenshot of the stacktrace further down.

If I after that crash open my game I can see that I am logged in and can do what I want (Invite friends etc.). But if I log out and then in again, the same problem occurs.

Additional info

  • I'm certain that I've got the hash key set up correctly, otherwise I wouldn't be able to call those other fb functions.
  • My manifest.xml is using the FBUnityPlayerActivity activity and I'm not extending UnityPlayerActivity in some other activity.
  • It looks like I'm coming back to my app for a split second before the screen goes black and the crash happens.
  • I'm using Facebook for Unity SDK 4.3.4, although I have tried 4.3.3 and 4.2.4. I'm seeing the same error on every version.
  • On the app page on facebook, the package name is correct and the Class is com.facebook.unity.FBUnityPlayerActivity.
  • Out of maybe 30 tries, one time I actually got back to my game after logging in. Without changing any code, next time I tried, it crashed.
  • I've tried to remove all of my scenes and only run the facebook example scene. Everything works in this case. (I later found out that this only works when runnning in portrait mode.)
  • Everything works on iOS. This error is just Android.

Suspicion

Of course I googled the stack trace, and it seems there's a similar problem here and here. From the SDK for Unity release notes, I noticed that even the latest version of the sdk uses Facebook for Android SDK 3.5.0, which points towards the same issue as the question I linked to. If that is indeed the case, is it possible for me to swap the underlying facebook for android sdk in the facebook for unity sdk and update it to a newer version myself?

Stacktrace

enter image description here

3
I am not sure about Unity but basically this problem occurs when Don't keep activities option is enable in the developers options settings.Abhishek Agarwal

3 Answers

2
votes

I found a solution. I don't understand it at all, but it works. Looking at the stacktrace it seems android can't resume the login activity. I tried running the example project and everything worked, as long as I was running in portrait mode. When I tilted my phone to landscape mode the same crash happened - even in the example scene. Looking at the LoginActivity in the manifest it looked like this:

<activity android:name="com.facebook.LoginActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
</activity>

Notice that the screenOrientation is set to portrait. It seems that this, in combination with the fact that my games orientation is set to sensorLandscape - android couldn't find the LoginActivity and thus crashing. I removed the android:screenOrientation="portrait" and everything works.

1
votes

I am not sure about Unity but basically this problem occurs when the calling activity is not live or destroyed. In android the method onActivityResult() is called after login. The Activity is destroyed forcefully by the mobile( Don't keep activities option enables in the developers options settings). Please Once cross check in the developers options setting that the Don't keep activities is enabled or disabled.

0
votes

The main problem is the key hash that generate unity. The key which shows unity is different you have to put in facebook settings.

Here's the solution!

  1. Unzip .apk file and extract META-INF\CERT.RSA file
  2. run keytool -printcert -file CERT.RSA
  3. notice SHA1 bytes are printed like 29:37:F1:CB:06…
  4. copy SHA1 bytes into HEX to BASE64 converter
  5. see your BASE64 key hash in output field

That Key BASE64 is the REAL key you have to put in facebook settings on https://apps.facebook.com/nameapp