Skip to content

[Bug] Analytics does not work on iOS if frameworks are not statically linked #1178

Closed
@p-lindberg

Description

@p-lindberg

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.18f1
  • Firebase Unity SDK version: 8.6.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Analytics
  • Other Firebase Components in use: None
  • Additional SDKs you are using: None
  • Platform you are using the Unity editor on: Mac
  • Platform you are targeting: iOS
  • Scripting Runtime: IL2CPP
  • Cocoapods version: 1.11.2
  • Xcode version: 13.1
  • MacOS version: 11.6

[REQUIRED] Please describe the issue here:

After integrating Firebase Analytics into a project I'm working on, I discovered the following issues on iOS:

  • No user-defined events gets reported, whereas the auto-reported events (session_start, user_engagement, etc) work fine. By user-defined events I mean those events that I am logging using FirebaseAnalytics.LogEvent().
  • FirebaseAnalytics.SetUserId and FirebaseAnalytics.SetUserProperty does not work.

The above was verified by:

  • Using the DebugView in Firebase to view incoming events: only auto-reported events show up.
  • Exporting all events to BigQuery and querying for distinct event names as well as user ids: only auto-reported event names are present, and all user ids are null.
  • Checking the device logs while running the app in Xcode: absolutely nothing is logged by Firebase when any of the above mentioned methods are called.

I then noticed that when the app starts, about 150 warnings of the following kind are printed to the log:

objc[2852]: Class FIRAAdExposureReporter is implemented in both /private/var/containers/Bundle/Application/2FDF37A0-448E-4A64-8018-80ECA33CF1D6/Test.app/Test (0x1023d9358) and /private/var/containers/Bundle/Application/2FDF37A0-448E-4A64-8018-80ECA33CF1D6/Test.app/Frameworks/UnityFramework.framework/UnityFramework (0x1061d9c00). One of the two will be used. Which one is undefined.

I found that enabling the option "Link frameworks statically" in the EDM4U iOS Resolver fixes both the warnings and the issues with Firebase Analytics. I can see how static linking resolves the duplicate implementation issue, but I'm uncertain as to why this is necessary, since the Firebase pods are only added to the UnityFramework target in the podfile. The podfile looks like this before applying the option:

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

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

And with "Link frameworks statically" the last line is updated to

use_frameworks! :linkage => :static

Now, I'm reporting this as a bug because the Firebase Unity SDK is ostensibly broken out-of-the-box because of this. As far as I can tell, there is no indication in any setup instructions or guides that this option needs to be enabled for things to work - and the option is disabled by default. Even worse, the SDK will build just fine and everything seems to work until you notice that your custom events do not get reported on iOS.

I have verified that the exact same result is achieved when setting up the quickstart project according to the instructions given, so this is not specific to my project.

Steps to reproduce:

  • Pull the quick-start repo
  • Launch the analytics testapp
  • Follow the instructions to add the Firebase SDK
  • Build for iOS
  • Observe that auto-reported events gets logged
  • Observe that custom events do not get logged
  • Toggle Link frameworks statically on in iOS Resolver settings and rebuild
  • Observe how everything works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: analyticsblocked-by-dependenciesIssues which is blocked by native Android/iOS SDK, backend or third-party dependencies.edm4uIssue related to External Dependency Manager for Unitytype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions