firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

[Bug] Gradle Build Failed [cannot find Symbol mUnityPlayer.quit()]

Open olimpsetz opened this issue 2 years ago • 5 comments

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2023.2.0b5
  • Firebase Unity SDK version: 11.4.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Messaging
  • Other Firebase Components in use: Auth
  • Additional SDKs you are using: Facebook, Appodeal, Xsolla
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Windows & Android
  • Scripting Runtime: IL2CPP
  • Pre-built SDK from the website
  • Gradle v7.6

[REQUIRED] Please describe the issue here:

An exception occurs when building on Android:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

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:

C:\Users\user\Documents\Projects\project\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\java\com\google\firebase\MessagingUnityPlayerActivity.java:77: error: cannot find symbol
      mUnityPlayer.quit();
                  ^
  symbol:   method quit()
  location: variable mUnityPlayer of type UnityPlayerForActivityOrService
Note: C:\Users\user\Documents\Projects\project\Library\Bee\Android\Prj\IL2CPP\Gradle\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

photo_2023-08-19_17-16-09

olimpsetz avatar Aug 19 '23 14:08 olimpsetz

Hi @olimpsetz,

Thanks for bringing this to our attention. In order to identify what could be causing this to happen, could you provide the complete steps you've taken before facing this issue? Also, does the issue persist when building using a stable version of the Unity editor (like an LTS version)?

paulinon avatar Aug 22 '23 13:08 paulinon

Hey @olimpsetz. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Aug 29 '23 01:08 google-oss-bot

Hello There !

I have the exact same issue on Unity 2023.2.0a22.

google\firebase\MessagingUnityPlayerActivity.java:77: error: cannot find symbol mUnityPlayer.quit(); ^ symbol: method quit() location: variable mUnityPlayer of type UnityPlayerForActivityOrService

To reproduce :

  • Create a project with Unity 2023.2.0.a22
  • Install Firebase analytycs and Messaging packages
  • Add the proper google-services.json
  • Try to build => fail => add ARM64 toggle in build settings due to android requiring 64bits assemblies to be available
  • Turn on IL2CPP in unity as ARM64 cannot be enabled with Mono
  • Build
  • Current error

seb776 avatar Aug 30 '23 16:08 seb776

I did a quick and dirty fix in case anyone has the same issue, put this in a file anywhere in Assets and run your build.

#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.IO;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class FixFirebaseAndroidBuild : IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }
    public void OnPreprocessBuild(BuildReport report)
    {
        var fileToFix = Path.Combine(Directory.GetCurrentDirectory(), "Assets\\Plugins\\Android\\MessagingUnityPlayerActivity.java");
        var content = File.ReadAllText(fileToFix);
        content = content.Replace("mUnityPlayer.quit();", "//mUnityPlayer.quit(); // Replaced as it causes a build error");
        File.WriteAllText(fileToFix, content);
        Debug.Log($"FixFirebaseAndroidBuild : Fixed file \"{fileToFix}\"");
    }
}
#endif

I simply comment the quit() call which seems to be absent in Unity 2023.

seb776 avatar Aug 31 '23 14:08 seb776

Thanks for calling this issue out. It does seem like the 2023.2 beta is removing the quit() call, but it is still present in 2023.1. I have a fix in place that should be out with the next release, but in the meantime you can either copy that fix to the Assets/Firebase/Editor/Messaging/FirebaseMessagingActivityGenerator.cs file, assuming you are using the unitypackage and can edit that file easily, or use the fix suggested by @seb776. I'm honestly not sure if the quit is still needed any more, it was put in place for a rare bug back in Unity 2017, but my fix is to swap it out for a call to destroy(), which as far as I can tell will have a similar effect of cleaning out anything cached before a new mUnityPlayer is created.

a-maurice avatar Aug 31 '23 23:08 a-maurice

Hey folks, I was able to verify that the fix has been applied. Testing on 11.9.0 seems to show no indication of build issues. I'll go ahead and close this thread now.

argzdev avatar Jun 25 '24 11:06 argzdev