firebase / quickstart-unity

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

iOS support is required on Windows for a Firebase project, causing Unity to not respond when I build for Android #1003

Open pardo162 opened 3 years ago

pardo162 commented 3 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

From what I have been able to observe the database does not give an answer, it does not give the data or an error. The problem appears in the APK not in the Editor. In the Editor it works.

Steps to reproduce:

do you need my Unity package name?

create a test database with: season = 1

1 create a 3D project in Unity. 2 create the script "testFB". 3 copy and paste the code (code at the end). 4 create any object in the scene "Create Empty". 5 add the script "testFB" to the new object. 6 create a Canvas then panel and inside a Text. 7 adjust the sizes of the GUI. 8 add the created Text to the script in Result. 9 the project must run in the editor. Should read "1" from the database. 10 build the project for Android and it will stop working

Relevant Code:

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

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Firebase;
using Firebase.Database;
using System.Text;
public class testFB : MonoBehaviour
{
    private FirebaseApp app;
    DependencyStatus dependencyStatus;
    public Text result;
    public int season;
    bool ready;
    void Start()
    {
        season = 10;
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {
                app = Firebase.FirebaseApp.DefaultInstance;
                ready = true;
            }
            else
            {
                Debug.LogError(System.String.Format(
                  "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
            }
        });
        StartCoroutine(ReadSeason());
    }
    private IEnumerator ReadSeason()
    {
        //Query season numbre should return: 1
        yield return new WaitForSeconds(1f);
        Debug.Log("done1");
        result.text = "done1";
        if (ready)
        {
            DataSnapshot snapshot;
            DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("season");
            var DBtask = reference.GetValueAsync();
            yield return new WaitUntil(predicate: () => DBtask.IsCompleted);
            //<-- Here it stops working, it just waits for an answer.

            result.text = "done2";
            Debug.Log("done2");
            if (DBtask.Exception != null)
            {
                Debug.Log("no");
                result.text = "no";
                result.text = DBtask.Exception.ToString();
            }
            else
            {
                Debug.Log("yes");
                result.text = "yes";
                snapshot = DBtask.Result;
                season = int.Parse(snapshot.Value.ToString());
                Debug.Log(season.ToString());
                result.text = season.ToString();
            }
        }
    }
}
paulinon commented 3 years ago

Hi @pardo162,

I have followed the steps you've listed, but the behavior in my Android build is the same as the editor's. To be specific, the text changed to "done1" then "1". With that, could you confirm if this issue persists with just that code and the Database SDK in your project?

If so, please provide the logs from the Android Logcat when running your app so that I can identify what's causing your issue.

Additionally, I noticed that you're using an LTS version of Unity. A new version was released recently (2020.3.1f1), so it's possible that updating your Unity editor may resolve your issue.

Let me know how it goes.

Thanks!

pardo162 commented 3 years ago

LogCast.txt Hi Here is the log I have not managed to fix anything. It does not give any error, it just does not respond. sometimes responds by taking several minutes. I also tried the latest version of Unity 2019 but nothing.

paulinon commented 3 years ago

Hi @pardo162,

The latest version of the Unity editor is version 2021.1.0. Could you try using this version and see if the issue is fixed? If not, please provide a minimal, reproducible example of your project. The cause of this behavior may come from within your project.

pardo162 commented 3 years ago

Hi ok I'm going to download that version

I have some questions: I installed IOS support because I had these errors is there any other way to solve these errors? could that be causing problems? I don't need IOS support Crash

another question in project settings > player > other settings > Api compatibility level for default it is Net.2 Standard should I change to .Net4?

the google-services shold be inside Assts folder or Assts / StreamingAssets?

patm1987 commented 3 years ago

Hi @pardo162 ,

It looks like it will be necessary to add iOS support to your Unity installation to use Firebase. It looks like this issue is related to googlesamples/unity-jar-resolver#412 (the error you're seeing in Google.IOSResolver_v1.2.164.dll) and appears to also effect Firebase dll's Firebase.Editor.dll and Firebase.Crashlytics.Editor.dll. A workaround mentioned in the linked bug suggests disabling some dlls to get it to work, but I would recommend against this in this case as you'd probably silently disable some of Crashlytics' core functionality.

Adding iOS support is the best workaround for now. I know that this isn't ideal and I will leave this open as a bug though since this shouldn't be required (in our testing, because of the dependency on CocoaPods, Windows versions of Unity cannot export a buildable XCode project with Firebase or other EDM4U libraries). Image included for others who stumble across this: image

The issue is that some of our libraries that edit XCode projects included using UnityEditor.iOS.Xcode; -- which can't be #ifdef'ed out since this ships as a compiled dll. The code is skipped if your target isn't, but because of the using statement, Unity tries to pull it in regardless. I'm told that this behaviour is different since earlier versions of Unity, but I can confirm that I see it on Windows with Unity 2020.3.1f1.

For your other questions:

pardo162 commented 3 years ago

I manage to solve the problem of IOS build support, now I only have Android build support, but my APK still does not respond. Unity 2021.1.0. is only giving me more problems. that version is new and unstable. I already have a minimal, reproducible example prepared. I created the APK (with the problem), an Export for Android Studio and The Unity project. if you give me an email I can share the folder.

pardo162 commented 3 years ago

What do i do now? I'm done with my game and the only thing I need to launch it is the connection to firebase have you already managed to replicate the bug?