BranchMetrics / xamarin-branch-deep-linking-attribution

The Branch Xamarin SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/xamarin/
MIT License
72 stars 17 forks source link

Does not work on iossimulator-arm64 #160

Closed rdavisau closed 10 months ago

rdavisau commented 10 months ago

Describe the bug

Generally developers on recent-ish (M1, M2, M3) machines will build and run arm64 simulator builds (RuntimeIdentifier: iossimulator-arm64). Branch SDK init fails on these builds, because the internal call to IOSNativeBranch.Branch.GetInstance(this.branchKey) returns null. Possibly the binding is not produced with a simulator arm64 slice? Switching to iossimulator-x64 resolves the issue, but means running an x64 build, which no one on arm64 wants to do :)

Steps to reproduce

  1. In csproj, set <PlatformTarget>arm64</PlatformTarget><RuntimeIdentifier>iossimulator-arm64</RuntimeIdentifier>
  2. Try to init SDK
  3. App crashes with NRE accessing the internal NativeBranch object

Expected behavior

SDK should init successfully

SDK Version

~8~ 9.0.1

Make and Model

iOS Simulator

OS

Any iOS

Additional Information/Context

No response

echo-branch commented 10 months ago

@rdavisau The older non-MAUI version of the Branch SDK used a fat binary instead of a xcframework. This is a problem since in a fat binary, so you can't have more than one arm slice. We only included the device version as that's more important. This is a known issue that wasn't fixed until the move to xcframeworks in the 9.x series.

https://github.com/BranchMetrics/xamarin-branch-deep-linking-attribution/releases/tag/7.1.2

This is fixed in the newer 9.x MAUI releases. By switching to xcframeworks.


BranchSDK.xcframework/ios-arm64_x86_64-simulator/BranchSDK.framework/BranchSDK: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64:Mach-O 64-bit dynamically linked shared library arm64]
BranchSDK.xcframework/ios-arm64_x86_64-simulator/BranchSDK.framework/BranchSDK (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64
BranchSDK.xcframework/ios-arm64_x86_64-simulator/BranchSDK.framework/BranchSDK (for architecture arm64):    Mach-O 64-bit dynamically linked shared library arm64
rdavisau commented 10 months ago

@echo-branch Thanks for the quick response.

Apologies, I specified SDK 8 as a reference to dotnet 8, obviously I should have been specifying the package version, which is 9.0.1.

Since you confirmed you already switched to xcframework, I attempted to create a minimal reproduction of the issue, and found that it does not reproduce. I spent a little time changing settings on the minimal project to match the breaking project but still could not get it to break. So, I'll close this as invalid and if I work out later there are a combination of project settings that make things not work I'll come back :)

rdavisau commented 8 months ago

In case any one else hits it - I eventually determined that the use of this obscure project setting was preventing Branch from initialising on arm64 simulator only:

<MtouchExtraArgs>--marshal-objectivec-exceptions:disable</MtouchExtraArgs>

I moved it to a release/device only property group and all works fine in debug and release.