firebase / quickstart-unity

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

[Bug] Adding ARCore pod breaks Custom Analytics Reporting on iOS device #1071

Closed adampsst closed 3 years ago

adampsst commented 3 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

When building to iOS, custom analytics are not being captured on the Firebase dashboard. However on Android they are. The only events on iOS which are captured are the default Firebase events, no custom evert data is showing. I have tried enablling Debug mode to check to see if they appear and it still does not show the data, again only the default Firebase events. We also have a test event being fired when the Firebase SDK's have been initialised and that is also not being captured on the dashboard (or debug view).

Steps to reproduce:

This occurs for all builds of our project on iOS, I have tried two different Firebase projects linked to Unity and neither show the data coming through.

Relevant Code:

Here is the initialisation code we are using:

using Cysharp.Threading.Tasks;
using Firebase.Analytics;
using Firebase.Crashlytics;
using Firebase.Extensions;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Mark.Utils
{
    public class FirebaseInit : MonoBehaviour
    {
        #region Serialized Fields

        [SerializeField] private string _sceneToLoad;

        #endregion

        #region Unity Methods

        private void Start()
        {
            Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Verbose;

            // Initialize Firebase
            Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
            {
                var dependencyStatus = task.Result;
                if (dependencyStatus == Firebase.DependencyStatus.Available)
                {
                    var app = Firebase.FirebaseApp.DefaultInstance;
                    FirebaseAnalytics.SetAnalyticsCollectionEnabled(true);
                    Crashlytics.IsCrashlyticsCollectionEnabled = true;

                    FirebaseAnalytics.LogEvent("TEST_EVENT", "test_param", "test_value");

                    Debug.Log("Firebase SDK Setup");
                }
                else
                {
                    Debug.LogError($"Could not resolve all Firebase dependencies: {dependencyStatus}");
                }

                UniTask.Run(LoadScene);
            });
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// Loads the next scene once we have initialized
        /// </summary>
        private async UniTask LoadScene()
        {
            await UniTask.SwitchToMainThread();
            Debug.Log($"[FirebaseInit] Loading scene: {_sceneToLoad}");
            SceneManager.LoadScene(_sceneToLoad);
        }

        #endregion
    }
}
paulinon commented 3 years ago

Hi @adampsst,

I noticed that your to log an event within the Start() function. It's possible that the event is not being reported because the FirebaseApp is not initiated yet. Naturally, the event cannot be enforced when you instantiate the object during gameplay.

With that, could you try the quickstart and see if the events aren't being reported from an iOS device?

adampsst commented 3 years ago

Hi @adampsst,

I noticed that your to log an event within the Start() function. It's possible that the event is not being reported because the FirebaseApp is not initiated yet. Naturally, the event cannot be enforced when you instantiate the object during gameplay.

With that, could you try the quickstart and see if the events aren't being reported from an iOS device?

Yeah, I will set some time aside to try this in the quickstart project as well. The even you can see in the code above is actually just there as a test, we have around 15-20 more events that are not being captured either throughout the project, but are on Android.

google-oss-bot commented 3 years ago

Hey @adampsst. 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 commented 3 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@adampsst if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

adampsst commented 3 years ago

Hi,

I have tested the quickstart project and I can see events coming through on iOS (custom events), but still not in our own project (only default events that the SDK logs as mentioned before).

Any suggestions where to go from here? Would a list of other packages we are using help?

Adam

adampsst commented 3 years ago

It would appear the issue is related to having ARCore Extentions and the Firebase SDK's in the same project. Once they are both added in I am no longer able to fire custom events, they never get logged. I can also see that there are errors relating to classes being implemented in multiple frameworks, which only occurs when the ARCore packages are added in.

To also be clear, we are part of the partner program with Google using the ARCorePartner versions.

adampsst commented 3 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@adampsst if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Please re-open

paulinon commented 3 years ago

Hi @adampsst,

Could you try using version 8.0.0 of the SDK and see if this resolves the issue?

adampsst commented 3 years ago

Hi @adampsst,

Could you try using version 8.0.0 of the SDK and see if this resolves the issue?

I have tried this version and it is still not working.

I have attached a file which contains various build errors inside xcode once i have Firebase products and ARCore Extensions installed in the same project.

Xcode Build Errors.txt

chkuang-g commented 3 years ago

Ah interesting. Did you install both Firebase and ARCore using .tgz? Like the instruction described here?

And what is the version number of ARCorePartner version?

Here is my observation:

  1. ARCore Extension tgz includes all the EDM4U libraries in its package. As a result, this blocks you from installing different version of EDM4U properly due to duplicated GUID. The latest ARCore includes EDM4U 1.2.162. To verify if this is the same to your project, check if ${YOUR_PROJECT_ROOT}/Library/PackageCache/com.google.ar.core.arfoundation.extensions@${SOME_RANDOM_STRING}/Editor/ExternalDependencyManager exists.
  2. EDM4U 1.2.164 added options to iOS Resolver to handle Swift Framework properly. In short, the older version EDM4U will generate Podfile like
    target 'UnityFramework' do
     pod 'Firebase/Core', '7.11.0'
    end

    And the newer version (1.2.164+) will generate Podfile like the following:

    target 'UnityFramework' do
     pod 'Firebase/Core', '7.11.0'
    end
    target 'Unity-iPhone' do
    end
    use_frameworks!

    Just curious about which version of EDM4U is in your project. Could you tell us the version number you saw on top of the settings windows using Assets > External Dependency Manager > iOS Resolver > Settings menu item? Screen Shot 2021-07-22 at 6 51 56 PM

  3. Due to the point 1 and point 2, this explains why you could not reproduce it in https://github.com/firebase/quickstart-unity/issues/1071#issuecomment-877187065. I think the only way to make this works is probably to install using .unitypackage :(. Like Firebase SDK from here and ARCore ones from here

Could you verify if either the removal of ARCore extension package works or installing everything using .unitypackage works?

If so, this is unfortunately. Since you are ARCore partner, I would recommend you to escalate this to ARCore team. I will escalate using internal channel as well once I hear from you.

Please let us know! Thank you.

adampsst commented 3 years ago

@chkuang-g Thanks for the long response.

So to be clear I am having the same issue with both the partner SDK version of ARCore as well as the current public release version. However the installation for these is slightly different:

Public Version This is installed by placing the pacakge into a GooglePackages folder, and then updating the manifest to point to the tgz file manually.

Partner Version This is installed by placing the extracted SDK inside its own folder under the Packages folder inside the project.

Now, in either case, I am able to fix the EDM4U issue, and I am able to build without issue. However, as linked above, we get a lot of errors relating to duplicate classes on iOS, which I believe is the root cause of the issue.

For reference, we are using 1.2.166 EDM4U.

I have struck up a conversation with ARCore Partner team as well, if you can push this along that would be great. But the fact this is also causing issues with the public release version is something we need to resolve.

chkuang-g commented 3 years ago

Could you post the content in your Podfile and Podfile.lock?

Also, did you see any error if you run pod install under your Xcode project?

adampsst commented 3 years ago

POD file contents below.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'

target 'UnityFramework' do
  pod 'ARCorePartner/CloudAnchorsPartner', :path => './../../../ARCorePartner/'
  pod 'Firebase/Analytics', '8.1.1'
  pod 'Firebase/Core', '8.1.1'
  pod 'Firebase/Crashlytics', '8.1.1'
  pod 'Firebase/RemoteConfig', '8.1.1'
end
target 'Unity-iPhone' do
end
use_frameworks!

Here is the pod install output:

adamgoodchild@Adams-Mac-mini Artly - iOS Artly - 1.3.0 % pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There are 5 dependencies from the Podfile and 16 total pods installed.

[!] The `UnityFramework [Release]` target overrides the `LD_RUNPATH_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-UnityFramework/Pods-UnityFramework.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `UnityFramework [ReleaseForProfiling]` target overrides the `LD_RUNPATH_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-UnityFramework/Pods-UnityFramework.releaseforprofiling.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `UnityFramework [ReleaseForRunning]` target overrides the `LD_RUNPATH_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-UnityFramework/Pods-UnityFramework.releaseforrunning.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `UnityFramework [Debug]` target overrides the `LD_RUNPATH_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-UnityFramework/Pods-UnityFramework.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.
adamgoodchild@Adams-Mac-mini Artly - iOS Artly - 1.3.0 % 

I have also attached the Podfile.lock file for you to look over.

Podfile.lock.txt

adampsst commented 3 years ago

Also, as mentioned earlier, this occurs when using the quickstart project along with the public ARCore Extensions SDK. Could someone in your team look at replicating this which may help resolve the issue?

chkuang-g commented 3 years ago

@adampsst Interesting. So you are using later version EDM4U. I will started some investigation this week.

A couple of question about your project

Thank you, Shawn

chkuang-g commented 3 years ago

@adampsst

TL;DR; I finally was able to reproduce the issue you described. I think the issue is with ARCore's pod, since by removing it, the Analytics event worked as intended. Also I found a workaround with a caveat: remove the following block in Podfile and run pod install again.

target 'Unity-iPhone' do
end
use_frameworks!

To prevent iOS resolver from adding this block back, disable the following settings in Assets > External Dependency Manager > iOS Resolver > Settings menu item. Screen Shot 2021-07-28 at 6 31 25 PM

CAVEAT: By doing so, your project will NOT be compatible to some other Unity packages which uses Swift framework, ex. Facebook Unity SDK, since their editor code add this block to Podfile regardlessly without any option. See #862

Unfortunately we have not found a solution that works for all scenario yet. That is why EDM4U added the options to add the following block to Podfile by default.

target 'Unity-iPhone' do
end
use_frameworks!

And we noticed that Admob and ARCore Pod may not compatible to these configuration. For some reason, this incompatibility broke Firebase Analytics custom event reporting.

I think ARCore team and Admob probably should update their Pod to make it works. At this point, the workaround with caveat is probably the only better option you have, or downgrade your Unity to 2019.2 or below before Unity introduce multi-target in Xcode project.

Let me contact our iOS team.

Reproduction steps:

Build Analytics quickstart and observe it working

  1. Use Firebase Unity SDK 8.1.0 and Unity 2020+. It does not matter Firebase is installed using .unitypackage or .tgz. I was using Unity 2020.1.17f1 as @adampsst specified in the first post. But I think this should be reproducible using Unity 2019.3+.
  2. Configure and build Firebase Analytics testapp as described in readme.md
  3. Enable DebugView as described here. I noticed that I need to add both -FIRAnalyticsDebugEnabled and -FIRDebugEnabled
  4. Open Debug View page on Firebase console.
  5. Build Xcode project and launch the app.
  6. Click on Log Login button. Observe the event login show up on Firebase console. It usually takes less than 1 minutes.

Add ARCore pod and observe it broken

  1. Uninstall the app from the iOS device.
  2. Modify Podfile to add ARCore/CloudAnchors like the following.
    target 'UnityFramework' do
     pod 'Firebase/Analytics', '8.3.0'
     pod 'Firebase/Core', '8.3.0'
     pod "ARCore/CloudAnchors", '~> 1.25.0'
    end
    target 'Unity-iPhone' do
    end
    use_frameworks!
  3. In a command line tool like iTerm, run pod install.
  4. Build Xcode project and and launch the app.
  5. Observe similar log attached in https://github.com/firebase/quickstart-unity/issues/1071#issuecomment-884951200
  6. Click on Log Login button.
  7. Note that different installation is a different Debug Device. You should see the device count increased. Use the dropdown menu to switch to different device. Screen Shot 2021-07-28 at 7 08 44 PM
  8. Observe the event like screen_view is logged but NOT login.

Apply workaround and observe it working

  1. Uninstall the app from the iOS device.
  2. Modify Podfile to remove target 'Unity-iPhone' and use_frameworks!, like the following:
    target 'UnityFramework' do
     pod 'Firebase/Analytics', '8.3.0'
     pod 'Firebase/Core', '8.3.0'
     pod "ARCore/CloudAnchors", '~> 1.25.0'
    end
  3. In a command line tool like iTerm, run pod install.
  4. Build Xcode project and and launch the app.
  5. Click on Log Login button.
  6. Note that different installation is a different Debug Device. You should see the device count increased. Use the dropdown menu to switch to a different device.
  7. Observe the event login is logged properly along with default Firebase events like screen_view.
chkuang-g commented 3 years ago

Hi @adampsst

We did a full investigation. Thanks to @paulb777!

TL;DR; The workaround for you is simple: link pods statically. Analytics and ARCore pods are static binary libraries which does not work very well with the Xcode project generated by Unity after 2019.3. Static binary pods are pretty common and are not going anyway anytime soon. Therefore, your best bet is to make sure pods are linked statically.

You can turn on the settings in Assets > External Dependency Manager > iOS Resolver > Settings

Screen Shot 2021-08-09 at 7 47 21 PM

Once checked, you should see this line in the newly generated Podfile

use_frameworks! :linkage => :static

This means the pods should be linked statically. This should work no matter pods are static libraries or dynamic libraries.

Troubleshooting

  1. We found the some other pods like FBSDKCoreKit from Facebook does not work very well with use_frameworks! :linkage => :static and you may see error like Undefined Symbol. What you need to do is to add a Dummy.swift to UnityFramework with the content like the following:
    import Foundation

    This will force Xcode project to link Swift libraries.

  2. We found that Facebook Unity SDK would forcefully add use_frameworks! to Podfile no matter there is such line presented already or now. See code. As a result, you will see duplicated lines like the following:
    use_frameworks! :linkage => :static
    use_frameworks!

    Since latter line will take effect, this will make Xcode project links pods dynamically again. Your best coarse of action is to remove the second line manually. I will file a bug to Facebook SDK to get this fixed.

That's it. Let us know if you are still experiencing the issue with these workarounds. I am thinking about adding some additional logic in EDM4U to turn on static linkage automatically. But that will be a FR from EDM4U side.

google-oss-bot commented 3 years ago

Hey @adampsst. 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 commented 3 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@adampsst if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.