firebase / firebase/firebase-unity-sdk

[Bug] Crash on Android 15 Emulator Triggered by Unreferenced CrashMethods.cs – Full Repro Steps (Related to #1180)

Open
#1,194 3 comments 0 reactions 0 assignees View on GitHub
api: messaging
Dominant language
C#
Stars
320
Forks
60
Avg merge
11h 15m
Merged PRs (30d)
11

Description

### Description

This issue is related to https://github.com/firebase/firebase-unity-sdk/issues/1180. I have managed to reproduce a crash 100% of the time using the following steps. In our project, if we include a class (`CrashMethods.cs`) that is not referenced by any other code, the app crashes on an Android 15 emulator during Firebase initialization—specifically, the callback from `CheckAndFixDependenciesAsync()` is never received, and the app subsequently crashes with a native error. Removing `CrashMethods.cs` (or ensuring that both `CrashMethods1()` and `CrashMethods2()` are completely removed) prevents the crash.

Notably, even if only one of the methods in `CrashMethods.cs` remains, the crash occurs. I have verified this in a completely new project as well, so it appears to be a direct interaction that triggers the crash. Additionally, when the project that crashes in Unity 2022 was opened in Unity6 (6000.0.35f1) and built, the crash still occurred.

### Reproducing the issue

1. **Create a new 3D project** in Unity 2022.3.23f1 (using Built-in Rendering).
2. **Add `google-services.json`** to the project (downloaded from the Firebase Console).
3. **Import `FirebaseMessaging.unitypackage`** into the project.
4. **Switch the platform to Android** in Build Settings.
5. In the Firebase settings, **enable Auto Resolution**.
6. In `gradleTemplate.properties`, add the following line to work around a Gradle build error:
```
android.aapt2FromMavenOverride=C:/Program Files/2022.3.23f1/Editor/Data/PlaybackEngines/AndroidPlayer/SDK/build-tools/34.0.0/aapt2.exe
```
7. Change the build settings to:
- **Target Architecture:** Arm64
- **Scripting Backend:** IL2CPP
- **minSDKVersion:** 25
- **targetSDKVersion:** 35
8. **Create `Initializer.cs`** and attach it to an object in the scene.
9. **Create `CrashMethods.cs`** and place it in the Assets folder (do not reference this class anywhere).
10. **Build and run the project on an Android 15 emulator.**
- **Expected behavior:**
- The log "Call CheckAndFixDependenciesAsync" is output.
- No log "CallBack CheckAndFixDependenciesAsync" is output, indicating that `CheckAndFixDependenciesAsync()` never returns.
- The app crashes with a native error shortly thereafter.
- **Note:**
- If `CrashMethods.cs` is removed entirely from the project, the crash does not occur.
- If either `CrashMethods1()` or `CrashMethods2()` remains (i.e., the file is not completely removed), the crash still occurs.

**Code Samples:**

*Initializer.cs:*
```csharp
using System.Collections;
using System.Collections.Generic;
using Firebase;
using Firebase.Extensions;
using UnityEngine;

public class initializer : MonoBehaviour
{
private FirebaseApp app;
void Start()
{
Debug.Log("Call CheckAndFixDependenciesAsync");
#if UNITY_ANDROID && !UNITY_EDITOR
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
Debug.Log("CallBack CheckAndFixDependenciesAsync");
var dependencyStatus = task.Result;
if (dependencyStatus == Firebase.DependencyStatus.Available) {
// Create and hold a reference to your FirebaseApp,
// where app is a Firebase.FirebaseApp property of your application class.
app = Firebase.FirebaseApp.DefaultInstance;
// Set a flag here to indicate whether Firebase is ready to use by your app.
} else {
UnityEngine.Debug.LogError(System.String.Format(
"Could not resolve all Firebase dependencies: {0}", dependencyStatus));
// Firebase Unity SDK is not safe to use here.
}
});
#endif
}
}
```

*CrashMethods.cs:*
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CrashMethods
{
private void CrashMethods1()
{
Firebase.Messaging.FirebaseMessaging.SubscribeAsync("")
.ContinueWith(task => { });
}

private void CrashMethods2()
{
Firebase.Messaging.FirebaseMessaging.UnsubscribeAsync("")
.ContinueWith(task => { });
}
}
```

**Environment:**
- **Host OS:** Windows 11
- **Unity Version:** 2022.3.23f1 (3D project using Built-in Rendering)
- **Android Build Settings:**
- Target Architecture: Arm64
- Scripting Backend: IL2CPP
- minSDKVersion: 25, targetSDKVersion: 35
- **Firebase Plugin:** FirebaseMessaging.unitypackage
- **gradleTemplate.properties:** Contains the aapt2 override as specified above.
- **Emulator:** Pixel 9 Pro using an x86-64 system image (Android 15, API Level 35, with 16KB page sizes not supported)
- **Emulator Image:**
![Emulator Image](https://github.com/user-attachments/assets/52c692e8-b352-45e2-8719-7c9c54101630)

Thank you for your attention to this matter. I look forward to your updates regarding this persistent crash.

### Firebase Unity SDK Version

11.9.0, 12.5.0, 12.6.0

### Unity editor version

2022.3.23f1, 6000.0.35f1

### Installation Method

.unitypackage

### Problematic Firebase Component(s)

Messaging

### Other Firebase Component(s) in use

_No response_

### Additional SDKs you are using

_No response_

### Targeted Platform(s)

Android

### Unity editor platform

Windows

### Scripting Runtime

IL2CPP

### Release Distribution Type

Pre-built SDK from https://firebase.google.com/download/unity

### Relevant Log Output

```shell

```

### If using CocoaPods for Apple platforms, the project's Podfile.lock

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.