facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
492 stars 257 forks source link

Crash on launch on iOS - [FBSDKGraphRequestConnection errorFromResult:request:] #208

Closed NumaNumaNuma closed 5 years ago

NumaNumaNuma commented 5 years ago

I'm using the sdk for analytics only. I'm getting rare crashes on app launch for some of our users (Unity 2018.2.19 and iOS 12.1) on 4G only (works fine on wifi). Xcode crash logs show:

image

At first I thought it was due to FB not being initialized properly but I'm using private void Awake() { if (FB.IsInitialized) { FB.ActivateApp(); } else { FB.Init(FB.ActivateApp); } } And I check that FB has been initialised before logging any analytics event.

Not sure if I'm doing something wrong or if this is a bug. Would love some feedback either way.

Thanks!

BlazingGillian commented 5 years ago

I'm getting this exact issue every time I launch on my iPhone 6s. It was not happening with the 7.14.1 version of the SDK, only 7.15.0. It means I'm completely unable to test my game without going back to an older version of the SDK (which I didn't seem to be getting any events from - hence why I upgraded). Would also love feedback if anyone else knows what might be wrong!

From Xcode the error appears to be: NSInvalidArgumentException: +[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x257dd4f80

NumaNumaNuma commented 5 years ago

Any news on this? We're getting the crash even without calling the API at all, just having it as part of the project. We have to remove the sdk completely for now...

BlazingGillian commented 5 years ago

I'm not sure if it'll be helpful but it turns out my problem was caused by the FacebookSettings object breaking when I updated the SDK. I just deleted it and made a new one and now everything is working again.

KylinChang commented 5 years ago

Hey @NumaNumaNuma @BlazingGillian, FB Unity SDK v7.15.1 is released and the issue should be fixed.

NumaNumaNuma commented 5 years ago

Hi @KylinChang, unfortunately I updated to the latest version and the issue is still occurring, the app crashes on launch every time. (It was also happening with 7.14.1 by the way).

KylinChang commented 5 years ago

Hi @NumaNumaNuma , thanks for your report. Can you provide more details about the iOS device you use, iOS version and maybe more stack traces?

NumaNumaNuma commented 5 years ago

I've seen it happen on a mix of iPhones and iPads running iOS 11.4, 12 and 12.1, so I'm not sure if it's device related (iPad Pro 11" 2018, iPhone X, iPhone XR, iPhone XS Max). The one interesting thing is for the people affected it works fine on wifi, but crashes 99% of the time on cellular. As for stack traces, I don't have anything besides the crash logs reported by xcode (hundreds of the same crash log). Could I email the .xccrashpoint file to you?

KylinChang commented 5 years ago

@NumaNumaNuma , sure, you can email .xccrashpoint file to me. Thanks for your report again!

NumaNumaNuma commented 5 years ago

@KylinChang Thanks, sent.

NumaNumaNuma commented 5 years ago

I tried using the sdk example scene AppEvents as a test, to rule out anything being caused by my project, and it 's crashing too. I didn't add anything to the scene besides this script to initialise the sdk that I placed on a gameobject in the scene (the example scene didn't have any init code by default). One thing I noticed is I'm getting a warning for calling init twice (in Awake and in OnApplicationPause), not sure if that's a problem?

` public class AnalyticsManager: MonoBehaviour {

    void Awake()
    {
        base.Awake();
        InitFBSDK();
    }

    public void InitFBSDK()
    {
        if (!FB.IsInitialized)
        {
            // Initialize the Facebook SDK
            FB.Init(InitCallback);
        }
        else
        {
            // Already initialized, signal an app activation App Event
            FB.ActivateApp();
        }
    }

    public void InitCallback()
    {
        if (FB.IsInitialized)
        {
            // Signal an app activation App Event
            FB.ActivateApp();
        }
        else
        {
            Debug.Log("Failed to Initialize the Analytics SDK");
        }
    }

    private void OnApplicationPause(bool pauseStatus)
    {
        // Check the pauseStatus to see if we are in the foreground
        // or background
        if (!pauseStatus)
        {
            //app resume
            if (FB.IsInitialized)
            {
                FB.ActivateApp();
            }
            else
            {
                //Handle FB.Init
                FB.Init(InitCallback);
            }
        }
    }

}`
kuljaninemir commented 5 years ago

We're seeing the same issue, except for our users it seems disabling wifi and going over 4G works. Maybe it's just something with a change of network connection that temporarily fixes it?

NumaNumaNuma commented 5 years ago

I think whichever is the fastest/slowest is causing problems at init time. Hopefully Kylin finds something in my logs🤞.

kuljaninemir commented 5 years ago

@KylinChang Let me know if you want our crash logs as well.

KylinChang commented 5 years ago

Hi @NumaNumaNuma @kuljaninemir , I think you can add -ObjC flag in exported xcode project to fix the problem. I will keep this issue open and please let me know if it still crashes with the flag. FYI, here is link about how to add the flag http://docs.onemobilesdk.aol.com/ios-ad-sdk/adding-objc-linker-flag-xcode.html

NumaNumaNuma commented 5 years ago

@KylinChang Thanks, I tried adding the flag, but it causes a link error: /Libraries/Plugins/iOS/libQuantumCore.a(QuantumCore.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Libraries/Plugins/iOS/libQuantumCore.a' for architecture arm64 I could disable bitcode but I'd rather not. Is there any way around this? edit: I'll disable bitcode and send to my patient 0, see if the issue is resolved.

NumaNumaNuma commented 5 years ago

All is good on my side and users reported the problem is gone. I'll put a version out to the world and if no one complains then we can call it fixed! @kuljaninemir is it fixed for you too?

kuljaninemir commented 5 years ago

I don't have contact with a patient 0 unfortunately so I'll have to push an update with this and see if the crashes stop.

NumaNumaNuma commented 5 years ago

No crashes so far, I think it's fixed! Thanks @KylinChang

kuljaninemir commented 5 years ago

Seems to work for us as well, thanks @KylinChang

Gornian commented 5 years ago

I have the same issue with my app. Version 7.15.1 Will try to upload next version with -ObjC flag. Sorry, maybe this is stupid question, but why this information is not in instruction with sdk integration?

GabrielCoriiu commented 5 years ago

Why not just add a post processing script to the Unity SDK?

[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
    if (buildTarget == BuildTarget.iOS)
    {
        string projPath = PBXProject.GetPBXProjectPath(path);

        PBXProject proj = new PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        string targetName = PBXProject.GetUnityTargetName();
        string targetGUID = proj.TargetGuidByName(targetName);

        proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");

        File.WriteAllText(projPath, proj.WriteToString());
    }
}
NumaNumaNuma commented 5 years ago

Yes please, That's what I ended up doing, but for others please add it to the post build process.

sharonreytan commented 5 years ago

I am encountering the exact same issue. What you mentioned here of adding the -ObjC did the trick for iPhone, but Apple rejected my binaries because of a crash on an iPad with IOS 12.1.4. Can anyone shed light on this please? I can't figure that out. The moment I go on cellular / flight mode / remove the Facebook SDK the error is gone. On Android everything works perfectly.

oct-test commented 5 years ago

@sharonreytan Did you try the solution mentioned above? Are you using any other analytics solutions?

sharonreytan commented 5 years ago

Yes, I added the -ObjC flag. It did solved the issue on my iPhone with IOS 12.1.4 that I test with, but Apple rejected my app, saying that it crashes on load on an iPad with IOS 12.1.4, on wifi. I use Game Analytics SDK in addition to Facebook SDK. The error comes from the Facebook SDK for sure, it is the one that throws the exception that crashes my app. Also, when I remove it everything works well, no crashes. I use Unity 2018.3.3, Facebook SDK 7.15.1 and xcode 10.1. The error happens only when the wifi is connected, with that flag, it happens on iPads but not on iPhones. it is not something in my code.

oct-test commented 5 years ago

@KylinChang Can you help here? Do you know if any update is coming up from Facebook?

GabrielCoriiu commented 5 years ago

@sharonreytan can you post the exception here?

sharonreytan commented 5 years ago

I will ask from Apple the crash log. Thank you everyone in advance! :)

GabrielCoriiu commented 5 years ago

I suggest that you connect your app to a platform that catches the crashes, like Unity Analytics or Firebase Crashlytics. Unity Analytics is just one switch away. Even if you fix this crash, it is probably not going to be the only one you are ever going to have. https://unitytech.github.io/clouddiagnostics/UnityCloudDiagnosticsSettingUp.html

sharonreytan commented 5 years ago

I do have such thing, but it doesn't catch that exception. I guess it is thrown on the wrapper level of Unity (the Swift stuff that handles such things like networking... That are OS related)

GabrielCoriiu commented 5 years ago

You can also see the crashes if you go to XCode -> Window -> Organizer -> Crashes (at the top, next to Archives) If they are symbolicated, try this to make them readable https://www.youtube.com/watch?v=kBA7H_uYf34

sharonreytan commented 5 years ago

The problem is that I can't reproduce the error locally, because I don't have an iPad, only an iPhone. Apple alerted me about this issue. As I said, on my iPhone everything works well with the -ObjC flag. The problem persists for iPads on wifi, and I can't simulate this with the simulator

GabrielCoriiu commented 5 years ago

The problem is that I can't reproduce the error locally, because I don't have an iPad, only an iPhone. Apple alerted me about this issue. As I said, on my iPhone everything works well with the -ObjC flag. The problem persists for iPads on wifi, and I can't simulate this with the simulator

The organizer shows all the crashes related to a specific version. https://8mobile.wordpress.com/2015/02/27/xcode-crashes-organizer/

sharonreytan commented 5 years ago

That's great. Thanks. I will add that

oct-test commented 5 years ago

@sharonreytan can you please share the crash report as soon as possible? I am actually holding up my build release because of this issue.

sharonreytan commented 5 years ago

Yep for sure. I am stuck with my release as well

oct-test commented 5 years ago

Yep for sure. I am stuck with my release as well

Did you find the crash reports?

sharonreytan commented 5 years ago

Not yet, it is a side project of mine

pmusolino commented 5 years ago

Same crash here :(

sharonreytan commented 5 years ago

@pmusolino Can you post the crash report please?

pmusolino commented 5 years ago

@sharonreytan It happens randomly. The next time it happens I'll post it

sharonreytan commented 5 years ago

I opened an empty project on Unity. It added a simple 3d cube in it and a particle system to it. I integrated to it the Facebook SDK and GameAnalytics SDK with my original app details. The error persists on that simple app - only on wifi things go wrong and I get a crash. That is the exact same crash I got on the app that I am trying to release. The error persist even if I remove the GameAnalytics SDK I use Unity 2018.3.3, Facebook SDK 7.15.1 and Xcode 10.1. This is the crash log:

2019-03-26 22:31:37.375996+0200 Jumpy[2798:888564] [DYMTLInitPlatform] platform initialization successful 2019-03-26 22:31:37.440830+0200 Jumpy[2798:888345] Built from '2018.3/staging' branch, Version '2018.3.3f1 (393bae82dbb8)', Build type 'Release', Scripting Backend 'il2cpp' 2019-03-26 22:31:37.446308+0200 Jumpy[2798:888345] -> registered mono modules 0x1035eb250 -> applicationDidFinishLaunching() 2019-03-26 22:31:39.096573+0200 Jumpy[2798:888345] Metal GPU Frame Capture Enabled 2019-03-26 22:31:39.098086+0200 Jumpy[2798:888345] Metal API Validation Disabled 2019-03-26 22:31:39.328250+0200 Jumpy[2798:888345] [Warning] Trying to set delaysTouchesBegan to NO on a system gate gesture recognizer - this is unsupported and will have undesired side effects -> applicationDidBecomeActive() GfxDevice: creating device client; threaded=1 Initializing Metal device caps: Apple A11 GPU Initialize engine version: 2018.3.3f1 (393bae82dbb8) 2019-03-26 22:31:39.653020+0200 Jumpy[2798:888616] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port רמקול (type: Speaker) 2019-03-26 22:31:39.740801+0200 Jumpy[2798:888616] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port רמקול (type: Speaker) 2019-03-26 22:31:40.107347+0200 Jumpy[2798:888345] +[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x26fc19f80 2019-03-26 22:31:40.152342+0200 Jumpy[2798:888345] Uncaught exception: NSInvalidArgumentException: +[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x26fc19f80 ( 0 CoreFoundation 0x0000000235d21ebc + 252 1 libobjc.A.dylib 0x0000000234ef1a50 objc_exception_throw + 56 2 CoreFoundation 0x0000000235c3fbbc + 0 3 CoreFoundation 0x0000000235d277bc + 1412 4 CoreFoundation 0x0000000235d2946c _CF_forwarding_prep_0 + 92 5 Jumpy 0x000000010315302c -[FBSDKGraphRequestConnection errorFromResult:request:] + 1720 6 Jumpy 0x00000001031519bc 64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke + 516 7 CoreFoundation 0x0000000235c074cc + 216 8 Jumpy 0x00000001031516ec -[FBSDKGraphRequestConnection completeWithResults:networkError:] + 540 9 Jumpy 0x0000000103150a30 -[FBSDKGraphRequestConnection completeFBSDKURLSessionWithResponse:data:networkError:] + 940 10 Jumpy 0x000000010314ebc4 36-[FBSDKGraphRequestConnection start]_block_invoke_2 + 80 11 libdispatch.dylib 0x00000002357596c8 + 24 12 libdispatch.dylib 0x000000023575a484 + 16 13 libdispatch.dylib 0x0000000235739b34 + 1012 14 CoreFoundation 0x0000000235cb1ce4 + 12 15 CoreFoundation 0x0000000235cacbac + 1964 16 CoreFoundation 0x0000000235cac0e0 CFRunLoopRunSpecific + 436 17 GraphicsServices 0x0000000237f25584 GSEventRunModal + 100 18 UIKitCore 0x000000026300cc00 UIApplicationMain + 212 19 Jumpy 0x0000000102766650 main + 160 20 libdyld.dylib 0x000000023576abb4 + 4 ) 2019-03-26 22:31:40.153484+0200 Jumpy[2798:888345] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x26fc19f80' First throw call stack: (0x235d21ea4 0x234ef1a50 0x235c3fbbc 0x235d277bc 0x235d2946c 0x10315302c 0x1031519bc 0x235c074cc 0x1031516ec 0x103150a30 0x10314ebc4 0x2357596c8 0x23575a484 0x235739b34 0x235cb1ce4 0x235cacbac 0x235cac0e0 0x237f25584 0x26300cc00 0x102766650 0x23576abb4) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

elguero44 commented 5 years ago

I got pretty much the same networkError from facebook happening with my new game:

2019-03-26 19:31:10.325566-0600 gamename[651:128389] +[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x228d7af80 2019-03-26 19:31:10.380123-0600 gamename[651:128389] Uncaught exception: NSInvalidArgumentException: +[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x228d7af80 ( 0 CoreFoundation 0x00000001ef9a5ebc + 252 1 libobjc.A.dylib 0x00000001eeb75a50 objc_exception_throw + 56 2 CoreFoundation 0x00000001ef8c3bbc + 0 3 CoreFoundation 0x00000001ef9ab7bc + 1412 4 CoreFoundation 0x00000001ef9ad46c _CF_forwarding_prep_0 + 92 5 gamename 0x0000000105ba3f2c -[FBSDKGraphRequestConnection errorFromResult:request:] + 1720 6 gamename 0x0000000105ba28bc 64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke + 516 7 CoreFoundation 0x00000001ef88b4cc + 216 8 gamename 0x0000000105ba25ec -[FBSDKGraphRequestConnection completeWithResults:networkError:] + 540 9 gamename 0x0000000105ba1930 -[FBSDKGraphRequestConnection completeFBSDKURLSessionWithResponse:data:networkError:] + 940 10 gamename 0x0000000105b9fac4 36-[FBSDKGraphRequestConnection start]_block_invoke_2 + 80 11 libdispatch.dylib 0x00000001ef3dd6c8 + 24 12 libdispatch.dylib 0x00000001ef3de484 + 16 13 libdispatch.dylib 0x00000001ef38a9a4 + 1068 14 CoreFoundation 0x00000001ef935ce4 + 12 15 CoreFoundation 0x00000001ef930bac + 1964 16 CoreFoundation 0x00000001ef9300e0 CFRunLoopRunSpecific + 436 17 GraphicsServices 0x00000001f1ba9584 GSEventRunModal + 100 18 UIKitCore 0x000000021cb40c00 UIApplicationMain + 212 19 gamename 0x0000000104dc01e0 main + 160 20 libdyld.dylib 0x00000001ef3eebb4 + 4 ) (lldb)

elguero44 commented 5 years ago

Funny though, I have the exact opposite happening. My game works great on WIFI, but as soon I'm on 3G it crashes. The crash report from above is on data 3G on a iPhone SE with iOS 12.2. Apple let it through review...

sharonreytan commented 5 years ago

@KylinChang Can you please have a look? This is a fatal error... I can't release my game because of that. Apple rejects my binaries. Might it be related to iOS >12.1.4?

sharonreytan commented 5 years ago

@elguero44 did you add the -ObjC flag? I guess Apple missed with your app. It seems to happen even on the simplest project. It is something on the FBSDK for Unity. My previous game was also approved and released but I see that there are crashes on iPads. It also had the FBSDK

NumaNumaNuma commented 5 years ago

Are you all seeing this since ios 12.2 / XCode 10.2 was released this week?

sharonreytan commented 5 years ago

I experienced it on iOS 12.1.4 and Xcode 10.1 as well. I will quote apple: "We discovered one or more bugs in your app when reviewed on iPad running iOS 12.1.4 on Wi-Fi.

Specifically, your app launched to a black screen and no further action was produced."

The black screen is the Unity splash screen. This version was submitted for review with the -ObjC flag

oct-test commented 5 years ago

Did anyone report this issue to Facebook bug tracker?

sharonreytan commented 5 years ago

@oct-test I did not. Can you please? I am far away from my project at the moment... And they require some stuff I can't gather right now