Crash on Android start due to "missing" UnityAnalytics

This question relates to:

Since that one was closed and I cannot reopen/reply I started a new one.
I am building for Android and am running into the following crash on app start:
Unable to find method CallIdentityTokenChanged in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.AnalyticsSessionInfo

I have tried the suggestions mentioned in the linked thread, however they do not fix the issue. We are using Unity 2022.3.38f1, building for target API 34.
We are not using UnityAnalytics, it is not visible under services nor is it present in the manifest.json

Below is our UnityCloudSettings.asset file, as you can see analytics is disabled.
After I run build it gets enabled.
I’ve tried using OnPreprocessBuild to make sure it is disabled, however something is enabling it.

%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!310 &1
UnityConnectSettings:
  m_ObjectHideFlags: 0
  serializedVersion: 1
  m_Enabled: 1
  m_TestMode: 0
  m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
  m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
  m_ConfigUrl: https://config.uca.cloud.unity3d.com
  m_DashboardUrl: https://dashboard.unity3d.com
  m_TestInitMode: 0
  CrashReportingSettings:
    m_EventUrl: https://perf-events.cloud.unity3d.com
    m_Enabled: 0
    m_LogBufferSize: 10
    m_CaptureEditorExceptions: 0
  UnityPurchasingSettings:
    m_Enabled: 1
    m_TestMode: 0
  UnityAnalyticsSettings:
    m_Enabled: 0
    m_TestMode: 0
    m_InitializeOnStartup: 0
    m_PackageRequiringCoreStatsPresent: 0
  UnityAdsSettings:
    m_Enabled: 0
    m_InitializeOnStartup: 0
    m_TestMode: 0
    m_IosGameId: 
    m_AndroidGameId: 
    m_GameIds: {}
    m_GameId: 
  PerformanceReportingSettings:
    m_Enabled: 0

I managed to remove UnityAnalytics from build by running the following code OnPreprocessBuild:

        var connectSettingsRes = EditorResources.Load<Object>("ProjectSettings/UnityConnectSettings.asset");
        var connectSettingsObj = new SerializedObject(connectSettingsRes);
        connectSettingsObj.FindProperty("m_Enabled").boolValue = false;
        connectSettingsObj.FindProperty("UnityAnalyticsSettings" ).FindPropertyRelative( "m_Enabled" ).boolValue = false;
        connectSettingsObj.ApplyModifiedProperties();
        AssetDatabase.SaveAssets();

Very bad implementation from Unity team, that such solutions are needed, but here we are.

3 Likes

Sorry to resurrect this thread, but we are now facing the same issue in Unity 6000.0.28f1 when building for iOS.

We have tried applying the force disabling of Unity Analytics inside the UnityConnectSettings.asset file but it still shows the errors in builds.

Unable to find type [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.AnalyticsSessionInfo
Unable to find method CallIdentityTokenChanged in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.AnalyticsSessionInfo
Unable to find method CallSessionStateChanged in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.AnalyticsSessionInfo
Unable to find type [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.AnalyticsSessionState
Unable to find type [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.Analytics.ContinuousEvent
Unable to find method RemoteConfigSettingsUpdated in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.RemoteConfigSettings
Unable to find type [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.RemoteConfigSettingsHelper/Tag
Unable to find method RemoteSettingsBeforeFetchFromServer in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.RemoteSettings
Unable to find method RemoteSettingsUpdateCompleted in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.RemoteSettings
Unable to find method RemoteSettingsUpdated in [UnityEngine.UnityAnalyticsModule.dll]UnityEngine.RemoteSettings

Any suggestions would be grateful on resolving this.

Adam

1 Like

Did you find a solution?
I am in the same situation. Latest Unity 6 on iOS with same errors.

I even tried adding back Analytics to the project but still get the same error when running on device.

I have Analytics working correctly in the Editor, but when running I get this same crash. Analytics is enabled, the Analytics package is installed.

EDIT: continued at

1 Like

Thank you! Was having the same issue and was able to remove Unity Analytics by implementing this.

Thanks you saved me. If anyone needs, I just made a quick copy and paste using @Adam_Poncle code

using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Experimental;
using UnityEngine;

public class AnalyticsRemover : IPreprocessBuildWithReport
{
    public int callbackOrder { get; }
    
    public void OnPreprocessBuild(BuildReport report)
    {
        var connectSettingsRes = EditorResources.Load<Object>("ProjectSettings/UnityConnectSettings.asset");
        var connectSettingsObj = new SerializedObject(connectSettingsRes);
        connectSettingsObj.FindProperty("m_Enabled").boolValue = false;
        connectSettingsObj.FindProperty("UnityAnalyticsSettings" ).FindPropertyRelative( "m_Enabled" ).boolValue = false;
        connectSettingsObj.ApplyModifiedProperties();
        AssetDatabase.SaveAssets();
        
        Debug.Log("Analytics disabled");
    }
}