[英]Unable to login with Facebook SDK for Unity on Android
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. 第一次调用FB.Login时,我被重定向到了Facebook,但是回到我的应用程序时似乎出现了问题。 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 附加信息
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.
从Unity SDK发行说明中,我注意到,即使是最新版的sdk,也将Facebook用于Android SDK 3.5.0,这与我链接到的问题相同。 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?
如果确实如此,我是否可以在Facebook中将基础facebook换成android sdk,然后在统一sdk中将其自己更新为新版本?
Stacktrace 堆栈跟踪
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.
查看stacktrace,似乎android无法恢复登录活动。 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:
查看清单中的LoginActivity,如下所示:
<activity android:name="com.facebook.LoginActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
</activity>
Notice that the screenOrientation is set to portrait. 请注意,screenOrientation设置为纵向。 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.
似乎这与我的游戏方向设置为sensorLandscape的事实相结合-android找不到LoginActivity并因此崩溃了。 I removed the android:screenOrientation="portrait" and everything works.
我删除了android:screenOrientation =“ portrait”,一切正常。
I am not sure about Unity but basically this problem occurs when the calling activity is not live or destroyed. 我不确定Unity的情况,但是基本上,当调用活动未激活或销毁时,会发生此问题。 In android the method onActivityResult() is called after login.
在android中,登录后将调用onActivityResult()方法。 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.
请一次交叉检查开发者选项设置中的“不保留活动”已启用或禁用。
The main problem is the key hash that generate unity. 主要问题是密钥哈希会产生统一性。 The key which shows unity is different you have to put in facebook settings.
显示统一性的键与您在Facebook设置中输入的不同。
Here's the solution! 这是解决方案!
That Key BASE64 is the REAL key you have to put in facebook settings on https://apps.facebook.com/nameapp 该密钥BASE64是您必须在https://apps.facebook.com/nameapp上的 Facebook设置中输入的REAL密钥
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.