IL2CPP stripping still breaks NSData and other wrappers: the packages' link.xml files are ignored and most constructors lack [Preserve]

Đang mở
#133 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, unity
Lĩnh vực
backend, mobile

Hướng nghiên cứu

Start by tracing InteropReference.PointerCast<T> to ReflectionUtility.CreateInstanceOrDefault and inspect the (IntPtr) constructors listed for Apple.Core and Apple.GameKit. Check how Unity discovers package link.xml files through IUnityLinkerProcessor.GenerateAdditionalLinkXmlFile, then reproduce with the stated iOS IL2CPP setup at Managed Stripping Level Low. Done means every wrapper reachable through PointerCast survives stripping without an app supplied link.xml.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug Plug-in - GameKit Plugin-in - Core

Describe the bug
Wrapper objects are created through reflection (InteropReference.PointerCast<T> calls ReflectionUtility.CreateInstanceOrDefault, which looks up the (IntPtr) constructor). Nothing calls those constructors directly, so IL2CPP managed stripping (Low and up) removes them, and the fallback Activator.CreateInstance throws MissingMethodException: Default constructor not found for type ....

Each package ships a link.xml with preserve="all", but in our builds Unity never passes those files to UnityLinker. In our Unity 6000.6.4f1 player builds, the link.xml files it uses are the ones under Assets/ and the ones packages generate through IUnityLinkerProcessor (for example Library/com.unity.services.core/link.xml). The files inside com.apple.unityplugin.core and com.apple.unityplugin.gamekit are not among them, and neither is the one inside com.unity.nuget.newtonsoft-json.

Only 14 constructors have [Preserve] today, all in GameKit, most added by #73 for #61. These 35 don't (main, 96e4a04):

  • Apple.Core: NSObject, NSData, NSString, NSError, NSException, NSNumber, NSNull, NSArray, NSArray, NSArrayInt64, NSArrayBoolean, NSArrayString, NSMutableArray, NSDictionary<TKey, TValue>, NSDictionary, NSDateComponents, Currency
  • Apple.GameKit: GKLeaderboard, GKLeaderboard.Entry, GKLeaderboardScore, GKLeaderboardSet, GKScoreChallenge, GKInvite, GKMatch, GKMatchDelegate, GKMatchedPlayers, GKMatchmakerViewController, GKMatchmakerViewControllerDelegate, GKTurnBasedExchange, GKTurnBasedExchangeReply, GKTurnBasedMatch, GKTurnBasedMatchmakerViewController, GKTurnBasedMatchmakerViewControllerDelegate, GKTurnBasedParticipant, GKVoiceChat

NSData is the one most apps will hit: GKLocalPlayer.FetchItemsForIdentityVerificationSignature() builds its signature and salt with PointerCast<NSData>, so Game Center identity verification (used for server-side sign-in) fails. #54 tried to fix exactly that and was closed because #73 was expected to cover it, but #73 only changed GameKit. #128 hit the same NSData MissingMethodException in October and was closed after the reporter switched to Minimal stripping.

To Reproduce

  1. iOS project with Apple.Core and Apple.GameKit, IL2CPP, Managed Stripping Level Low, no link.xml of your own.
  2. Sign in to Game Center and call GKLocalPlayer.Local.FetchItemsForIdentityVerificationSignature().
  3. MissingMethodException for Apple.Core.Runtime.NSData.

Expected behavior
Every wrapper reachable through PointerCast survives stripping without each project adding its own link.xml.

Environment
Unity 6000.6.4f1, iOS, IL2CPP, Managed Stripping Level Low. Apple.Core 3.3.0 / Apple.GameKit 4.1.0 (27.0, ffe6174); also checked main (96e4a04). We haven't re-run this on 4.1.0 because our own link.xml prevents it; the NSData failure is the one #128 reports.

Additional context
Either register the shipped link.xml through IUnityLinkerProcessor.GenerateAdditionalLinkXmlFile (the way com.unity.services.core does), or put [Preserve] on every (IntPtr) constructor. Our workaround is a link.xml under Assets:

<linker>
  <assembly fullname="Apple.Core" ignoreIfMissing="1" preserve="all" />
  <assembly fullname="Apple.GameKit" ignoreIfMissing="1" preserve="all" />
</linker>
Ngôn ngữ chính
C#
Star
1k
Fork
257
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apple/unityplugins

Tất cả issue của apple/unityplugins

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.