From 4ef24bd02e5f0cab29e17774a5b4ebf49bef770c Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 9 Jun 2026 20:29:10 +1200 Subject: [PATCH] fix(audience): prevent IL2CPP stripping of Unity hooks assembly Games using IL2CPP with High stripping and no project-level link.xml lose all Unity context fields (userAgent, locale, screen, timezone). The linker strips Immutable.Audience.Unity entirely when it finds no call sites, so the [RuntimeInitializeOnLoadMethod] hooks never fire and ContextProvider is never registered. [assembly: AlwaysLinkAssembly] forces the linker to process the assembly regardless of call sites. [Preserve] on AudienceUnityHooks keeps Install() alive once the assembly is included. [Preserve] alone is insufficient because the linker skips the assembly before evaluating attributes. Fixes SDK-480. Co-Authored-By: Claude Sonnet 4.6 --- src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs b/src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs index ada1f446..6da3699e 100644 --- a/src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs +++ b/src/Packages/Audience/Runtime/Unity/AudienceUnityHooks.cs @@ -4,9 +4,13 @@ using System.Collections.ObjectModel; using Immutable.Audience.Unity.Mobile; using UnityEngine; +using UnityEngine.Scripting; + +[assembly: AlwaysLinkAssembly] namespace Immutable.Audience.Unity { + [Preserve] internal static class AudienceUnityHooks { // Captured at SubsystemRegistration so the Install Referrer provider