firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

Crashlytics + IL2CPP does not work #1290

Closed nitzanwilnai closed 1 year ago

nitzanwilnai commented 2 years ago

[READ] For Firebase Unity SDK issues, please report to Firebase Unity open-source

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.) Clean project, using Crashlytics quick start. Building with Mono WORKS, building with IL2CPP does not:

Unity : Disable module 'crashlytics' for 'Firebase.Crashlytics.Crashlytics, Firebase.Crashlytics'

Longer log: 06-24 13:51:45.842 1864 2109 I ActivityTaskManager: Displayed com.fourxp.mergeup/com.unity3d.player.UnityPlayerActivity: +210ms 06-24 13:51:45.844 17707 17738 I Unity : MemoryManager: Using 'Dynamic Heap' Allocator. 06-24 13:51:45.857 17707 17738 I Unity : SystemInfo CPU = ARM64 FP ASIMD AES, Cores = 8, Memory = 5593mb 06-24 13:51:45.857 17707 17738 I Unity : SystemInfo ARM big.LITTLE configuration: 2 big (mask: 0xc0), 6 little (mask: 0x3f) 06-24 13:51:45.857 17707 17738 I Unity : ApplicationInfo com.fourxp.mergeup version 0.1 build 17014145-bd67-4b23-a737-0c877bff1ecf 06-24 13:51:45.857 17707 17738 I Unity : Built from '2020.3/staging' branch, Version '2020.3.25f1 (9b9180224418)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a', Stripping 'Enabled' 06-24 13:51:45.878 17707 17738 I Unity : Company Name: DefaultCompany 06-24 13:51:45.878 17707 17738 I Unity : Product Name: FirebaseClean2 06-24 13:51:47.178 723 723 E TimeStats: [3533]-[SurfaceViewcom.fourxp.mergeup/com.unity3d.player.UnityPlayerActivity#0]-timeRecords is at its maximum size[64]. Ignore this when unittesting. 06-24 13:51:48.146 17707 17738 I Unity : Disable module 'analytics' for 'Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics' 06-24 13:51:48.146 17707 17738 I Unity : Firebase.FirebaseApp:InitializeAppUtilCallbacks() 06-24 13:51:48.146 17707 17738 I Unity : Firebase.FirebaseApp:CheckDependenciesAsync() 06-24 13:51:48.146 17707 17738 I Unity : Firebase.FirebaseApp:CheckAndFixDependenciesAsync() 06-24 13:51:48.146 17707 17738 I Unity : FirebaseClean:Start() 06-24 13:51:48.146 17707 17738 I Unity : 06-24 13:51:48.148 17707 17738 I Unity : Disable module 'crashlytics' for 'Firebase.Crashlytics.Crashlytics, Firebase.Crashlytics' 06-24 13:51:48.148 17707 17738 I Unity : Firebase.FirebaseApp:InitializeAppUtilCallbacks() 06-24 13:51:48.148 17707 17738 I Unity : Firebase.FirebaseApp:CheckDependenciesAsync() 06-24 13:51:48.148 17707 17738 I Unity : Firebase.FirebaseApp:CheckAndFixDependenciesAsync() 06-24 13:51:48.148 17707 17738 I Unity : FirebaseClean:Start()

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? (eg 100%, 1/5 etc) 100% repro rate. Use Crashlytics quick start. Switch to IL2CPP. Crashlytics will not load.

What happened? How can we make the problem occur? 100% repro rate. Use Crashlytics quick start. Switch to IL2CPP. Crashlytics will not load. Disable module 'crashlytics' for 'Firebase.Crashlytics.Crashlytics

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

Relevant Code:

Clean new project. Add Crashlytics. Set scripting runtime to IL2CPP.

// TODO(you): code here to reproduce the problem

https://drive.google.com/file/d/15kHj1rh8SUgrOUaFsxhiSQBBFbCOgB8T/view?usp=sharing

nitzanwilnai commented 2 years ago

Note - the issue also happens with iOS builds (as they use IL2CPP). Going back to Crashlytics version 8.9.0 FIXES THE ISSUE!

EDIT - 8.10.0 breaks IL2CPP, and it has not been fixed since.

paulinon commented 2 years ago

Hi @nitzanwilnai,

Thanks for reporting this. While I try to replicate this issue, could you verify if this behavior persists using our quickstart sample?

nitzanwilnai commented 2 years ago

Hi @paulinon - It seems like 9.1.0 DOES work on the quickstart sample when setting it to IL2CPP. I'll dig into what is different between it and my quickstart. Does my sample project work for you? (Or following your quickstart guide)

paulinon commented 2 years ago

Hi @nitzanwilnai,

I've tried the sample project you provided, and the crashes aren't being reported on the dashboard. What's odd is that this happens in both Mono and IL2CPP.

I also noticed that you followed along our documentation related to testing crashes, so I did the same thing in a blank project, and I was able to see the crashes being reported using IL2CPP. With that, could you verify if reimporting the SDK makes any difference?

Whyser commented 2 years ago

Hey,

I had this issue as well. It seems that Unity might be stripping the library (or something). Because if I add this piece of code: Debug.Log("Is crashlytics enabled: " + Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled); It will then work as intended and enable the module (this will NOT enable other libraries, in my case Firebase Analytics was disabled also, unless I referenced something in FirebaseAnalytics namespace).

Note: I do not use proguard/minify in my project.

nitzanwilnai commented 2 years ago

@paulinon Re-importing does not solve the problem.

nitzanwilnai commented 2 years ago

Adding the debug.log DOES solve the problem!

paulinon commented 2 years ago

Thanks for the update, @nitzanwilnai. Glad to hear that you resolved the issue.

I'll be closing this for now. Let me know if an issue arises.

Whyser commented 2 years ago

@paulinon Uhm, why close the issue unless it has been fixed? Either update documentation to state that we need to reference the library or issue an actual fix? This is quite serious.

nitzanwilnai commented 2 years ago

@paulinon I second what @Whyser said. I think the documentation needs to be updated and/or the issue fixed. Something changed since 8.9.0 to cause this.

nitzanwilnai commented 2 years ago

To be clear, adding the line Debug.Log("Is crashlytics enabled: " + Firebase.Crashlytics.Crashlytics.IsCrashlyticsCollectionEnabled); AFTER Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance; Fixes the issue.

paulinon commented 2 years ago

Hi folks,

Apologies for the misunderstanding. I've tried the workaround you provided, but it had no effect in my implementation. Given this odd behavior, could you verify if the issue persists in the sample project provided by @nitzanwilnai? Without using the workaround, are the crashes being reported when using Mono?

Whyser commented 2 years ago

Not sure what you're asking @paulinon? nitzanwilnai's already said he tested the 'quickstart-sample' and that it did work. And you already tested nitzanwilnai's and confirmed that it didnt work. The difference in these projects seems to be:

quickstart-sample references(/uses) the Crashlytics APIs in the SDK in some scripts. My project didn't (and it seems neither does nitzanwilnais')

nitzanwilnai commented 2 years ago

Hi @paulinon, adding the line to the sample project (from the google drive link above) DOES fix the issue for me in IL2CPP. Mono always worked and continues to work.

paulinon commented 2 years ago

Thanks for the information, folks. I was finally able to observe this behavior in another blank project, and the workaround you provided worked.

I'll be relaying my observations to the team, and I'll keep this open for future updates.

nitzanwilnai commented 2 years ago

@Whyser Thanks for providing the fix. You rock!

dafeidafei1993 commented 2 years ago

I have the same problem as you. The project we use is unity2019.4.40f1. That is, crashlytics works normally in mono. In il2cpp, non serious error reports cannot be caught, However, it can be counted that the crash error report (this crash error report is not the official test crash, but the crash generated by [unityengine.diagnostics.utils.forcecrash (forcedcrashcategory.accessviolation (using unityengine. Diagnostics)]. This makes us very confused. We observed in the log that it seems that Google Analytics in the unity project packaged by 2libcc did not initialize successfully as the project packaged by mono. Similarly, we cannot see the correct symbolic file after symbol uploading.

a-maurice commented 1 year ago

Hi all,

We've identified the issue, when using il2cpp code stripping is more aggressive, and it is removing the Crashlytics symbols. In previous versions, there was a link.xml file that told the compiler to preserve those symbols, but that file was accidentally removed.

We will get this added in the next release, but you can fix this locally by adding Firebase/Plugins/Crashlytics/link.xml with the following content:

<linker>
<assembly fullname="Firebase.Crashlytics" ignoreIfMissing="1">
    <namespace fullname="Firebase.Crashlytics" preserve="all"/>
</assembly>
</linker>
Whyser commented 1 year ago

Thanks for this @a-maurice! Just heads up, this issue occurred for Analytics package as well. But I'm guessing you're adding the link.xml to all packages.

a-maurice commented 1 year ago

Hmm, we've never had one for Analytics previously, though that doesn't necessarily mean we shouldn't. A lot of the initialization logic is a bit complicated, and I know Crashlytics requires the C# initialization logic to correctly register crashes from C#, meanwhile I'm less sure that Analytics actually requires C# initialization. Thanks for the heads up, I'll take a deeper look into it.

Whyser commented 1 year ago

Well, I think it doesn't happen as easily with Analytics since you're most likely referencing some API call like "SendEvent" or similar, while in Crashlytics you never really need to call anything (other than base initialization). With this said, I only confirmed this by checking the logs (which said Analytics module was disabled). I did not verify in any other way if user actually got "recorded" or not.

a-maurice commented 1 year ago

Looking into the Analytics logic, I believe it is fine as is. The logic doesn't need the Unity side of Analytics to initialize to actually start collecting data, it is only if custom events are being added, at which point the C# code is referenced, so it will initialize.

The latest release, 9.2.0, just came out with the Crashlytics fix, so I'm marking this as closed. Thanks again for bringing this to our attention.