facebook unity sdk 6.0崩溃应用程序在第二次登录

时间:2014-09-09 18:02:08

标签: android facebook unity3d facebook-unity-sdk

使用facebook unity sdk 6.0创建了一个简单的应用程序。

在启动功能中调用init facebook。

有一个按钮调用登录,登录回调只输出字符串。

使用android 4.4.2在三星galaxy s5上运行。

问题(100%可重复):

 1. First time click login button, get the facebook login screen.
 2. Click exit button, back to app.
 3. Click login button again, app crashed.

崩溃转储:

W/dalvikvm(16020): threadid=1: thread exiting with uncaught exception (group=0x417f3da0)
V/SmartFaceService - 3rd party pause(  704): onReceive [android.intent.action.ACTIVITY_STATE/com.xxxxx.testfacebook/create]
I/SpenGestureManager(  704): setFocusWindow21055
D/PointerIcon(  704): setMouseIconStyle1 pointerType: 1001iconType:101 flag:0
D/PointerIcon(  704): setMouseCustomIcon IconType is same.101
D/PointerIcon(  704): setHoveringSpenIconStyle1 pointerType: 10001iconType:1 flag:0
D/PointerIcon(  704): setHoveringSpenCustomIcon IconType is same.1
E/AndroidRuntime(16020): FATAL EXCEPTION: main
E/AndroidRuntime(16020): Process: com.xxxxx.testfacebook, PID: 16020
E/AndroidRuntime(16020): java.lang.Error: FATAL EXCEPTION [main]
E/AndroidRuntime(16020): Unity version     : 4.5.3f3
E/AndroidRuntime(16020): Device model      : samsung SAMSUNG-SM-G900A
E/AndroidRuntime(16020): Device fingerprint: samsung/klteuc/klteatt:4.4.2/KOT49H/G900AUCU1ANCE:user/release-keys
E/AndroidRuntime(16020): 
E/AndroidRuntime(16020): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.testfacebook/com.facebook.unity.FBUnityLoginActivity}: java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
E/AndroidRuntime(16020):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
E/AndroidRuntime(16020):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
E/AndroidRuntime(16020):    at android.app.ActivityThread.access$900(ActivityThread.java:169)
E/AndroidRuntime(16020):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
E/AndroidRuntime(16020):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(16020):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(16020):    at android.app.ActivityThread.main(ActivityThread.java:5476)
E/AndroidRuntime(16020):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(16020):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(16020):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
E/AndroidRuntime(16020):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
E/AndroidRuntime(16020):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(16020): Caused by: java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
E/AndroidRuntime(16020):    at com.facebook.Session.open(Session.java:1223)
E/AndroidRuntime(16020):    at com.facebook.Session.openForPublish(Session.java:519)
E/AndroidRuntime(16020):    at com.facebook.unity.FBLogin.sessionOpenRequest(FBLogin.java:113)
E/AndroidRuntime(16020):    at com.facebook.unity.FBLogin.login(FBLogin.java:98)
E/AndroidRuntime(16020):    at com.facebook.unity.FBUnityLoginActivity.onCreate(FBUnityLoginActivity.java:14)
E/AndroidRuntime(16020):    at android.app.Activity.performCreate(Activity.java:5451)
E/AndroidRuntime(16020):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
E/AndroidRuntime(16020):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
E/AndroidRuntime(16020):    ... 11 more
W/ActivityManager(  704):   Force finishing activity com.xxxxx.testfacebook/com.facebook.unity.FBUnityLoginActivity
I/SQLiteSecureOpenHelper(27856): getWritableDatabase(pwd)
I/SQLiteSecureOpenHelper(27856): getDatabaseLocked(b,b,pwd)...
W/ActivityManager(  704):   Force finishing activity com.xxxxx.testfacebook/com.unity3d.player.UnityPlayerNativeActivity
V/SmartFaceService - 3rd party pause(  704): onReceive [android.intent.action.ACTIVITY_STATE/com.xxxxx.testfacebook/pause]
I/dumpstate(16164): begin
I/SpenGestureManager(  704): setFocusWindow0
D/EnterpriseDeviceManager(  704): ContainerId: 0
D/PointerIcon(  704): setMouseIconStyle1 pointerType: 1001iconType:101 flag:0
D/PointerIcon(  704): setMouseCustomIcon IconType is same.101
D/PointerIcon(  704): setHoveringSpenIconStyle1 pointerType: 10001iconType:1 flag:0
D/CrashAnrDetector(  704): processName: com.xxxxx.testfacebook
D/PointerIcon(  704): setHoveringSpenCustomIcon IconType is same.1
D/CrashAnrDetector(  704): broadcastEvent : com.xxxxx.testfacebook data_app_crash

4 个答案:

答案 0 :(得分:2)

在我的其他帐户上提供了一个更永久的解决方案" Helath":

http://answers.unity3d.com/questions/743523/facebook-sdk-cancelled-login-crash.html

Fair Point,这是我在另一个网站上发布的帖子:

如果状态是"登录失败&#34>他们基本上忘记刷新会话。以及"已关闭"。

如果你愿意,你可以将facebook sdk导入eclipse并更改FBLogin.Java的第63行

if (SessionState.CLOSED.equals(session.getState())) {
            session = new Builder(FB.getUnityActivity()).setApplicationId(session.getApplicationId()).build();
            Session.setActiveSession(session);
        }

   if (SessionState.CLOSED.equals(session.getState()) || SessionState.CLOSED_LOGIN_FAILED.equals(session.getState())) {
                session = new Builder(FB.getUnityActivity()).setApplicationId(session.getApplicationId()).build();
                Session.setActiveSession(session);
            }

然后将项目导出为jar,仅包含类文件,如Plugins / Android / facebook / bin文件夹中的classes.jar。

编辑:如果我上传课程可能会更容易。我正在使用...在此处下载:http://speedy.sh/QPgUp/classes.jar并将其放在Plugins / Android / facebook / bin文件夹中。< / p>

编辑2:如果你仍然遇到这个问题,Facebook似乎已经在2014年10月20日发布了他们的修复程序。所以更新到他们最新的sdk现在解决了这个问题!

答案 1 :(得分:1)

找到了一个有趣的解决方案。

就像我在James Baxter的回答中评论一样,如果你在登录前每次都调用init,即使你已经调用了“FB.Init(),也没有崩溃。你只需要调用一次,只需要调用一次。 “错误。

但是,从文档中可以看出,“此函数只能在对象的生命周期内调用一次;以后的调用会导致未定义的行为。”。

对象意味着场景?还是另一个游戏对象?

答案 2 :(得分:0)

您能否分享您的统一代码 - 显然您仍然登录,并且不应该再次按下登录按钮。

我们使用Facebook SDK的方式是调用FB.Init然后在回调中使用FB.IsLoggedIn,然后再调用FB.Login(如果需要)......

答案 3 :(得分:0)

以下是代码:

你可以看到,在调用登录函数之前,它将检查FB.IsLoggedIn,与init函数一样。

public class FacebookManager
{
    public void FBInit()
    {
        if (!FB.IsInitialized)
            FB.Init(OnInitComplete, OnHideUnity);
    }

    private void OnInitComplete()
    {
        UnityEngine.Debug.LogError("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
    }

    private void OnHideUnity(bool isGameShown)
    {
        UnityEngine.Debug.LogError("Is game showing? " + isGameShown);
    }

    public void FBLogin()
    {
        FBInit();
        if (!FB.IsLoggedIn)
        {
            FB.Login("publish_actions", LoginCallback);
        }

    }

    void LoginCallback(FBResult result)
    {
        if (result.Error != null)
        {
            UnityEngine.Debug.LogError("Error Response:\n" + result.Error);
            UnityEngine.Debug.LogError("Error Response:\n" + result.Text);
        }
        else if (!FB.IsLoggedIn)
        {
            UnityEngine.Debug.LogError("Login cancelled by Player");
        }
        else
        {
            UnityEngine.Debug.LogError("Login was successful!");
        }
    }

    public void CallFBLogout()
    {
        FB.Logout();
    }
}