fix(audience): prevent IL2CPP stripping of Unity hooks assembly#790
Open
nattb8 wants to merge 1 commit into
Open
fix(audience): prevent IL2CPP stripping of Unity hooks assembly#790nattb8 wants to merge 1 commit into
nattb8 wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes SDK-480.
Problem
Games built with IL2CPP + High stripping silently lose all Unity context fields (
userAgent,locale,screen,timezone) from every event. The linker strips the entireImmutable.Audience.Unityassembly when it finds no call sites into it — so the[RuntimeInitializeOnLoadMethod]hook never fires andContextProvideris never registered. OnlylibraryandlibraryVersionsurvive because they come fromImmutable.Audience.Runtime, which has direct references keeping it alive.The SDK ships a
link.xmlto guard against this, but Unity's linker skips it for packages loaded via afile:path outside the project tree. Studios without a project-levellink.xmlfallback hit this silently.Confirmed in production on project 18282: ~97% of 0.3.0 events are missing
userAgent. All 0.2.2 events from the same project had it — the regression correlates with them switching to an IL2CPP + High stripping build around the 0.3.0 upgrade.Fix
Two lines in
AudienceUnityHooks.cs:[assembly: AlwaysLinkAssembly]— forces the linker to process the assembly regardless of call sites[Preserve]on the class — keepsInstall()alive once the assembly is included[Preserve]alone is not enough: if the linker skips the assembly entirely, it never evaluates the attribute.Test plan
link.xmluserAgent,locale,screen,timezone)PersistentDataPath is requiredcrash on init