Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios binding library with xcframework fails to link #21142

Closed
akghasemi opened this issue Aug 28, 2024 · 22 comments
Closed

ios binding library with xcframework fails to link #21142

akghasemi opened this issue Aug 28, 2024 · 22 comments
Labels
binding-projects Issue or PR that affects binding projects need-info Waiting for more information before the bug can be investigated

Comments

@akghasemi
Copy link

akghasemi commented Aug 28, 2024

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

VS2022 17.11.2

Description

I have built an Ios binding library with xcframework and I am using Unity Ads sdk for ios. the binding project compiles well without any error but when I try to use this library in my project at last step I get this error.
I am using visual studio on windows and paired it with Apple mac mini with M2 chip.
I also attached MsBuild binlog

Undefined symbols for architecture arm64: "_$s15_ObjectiveCTypes01_A11CBridgeablePTl", referenced from: l_got.$s15_ObjectiveCTypes01_A11CBridgeablePTl in UnityAds(UnityAds-arm64-master.o) "_$s16FloatLiteralTypes013ExpressibleByaB0PTl", referenced from: l_got.$s16FloatLiteralTypes013ExpressibleByaB0PTl in UnityAds(Google_Protobuf_Duration+Extensions.o) l_got.$s16FloatLiteralTypes013ExpressibleByaB0PTl in UnityAds(Google_Protobuf_Value+Extensions.o) l_got.$s16FloatLiteralTypes013ExpressibleByaB0PTl in UnityAds(Google_Protobuf_Wrappers+Extensions.o) "_$s17StringLiteralTypes013ExpressibleByaB0PTl", referenced from: l_got.$s17StringLiteralTypes013ExpressibleByaB0PTl in UnityAds(UnityAds-arm64-master.o) l_got.$s17StringLiteralTypes013ExpressibleByaB0PTl in UnityAds(Google_Protobuf_Value+Extensions.o) l_got.$s17StringLiteralTypes013ExpressibleByaB0PTl in UnityAds(Google_Protobuf_Wrappers+Extensions.o) "_$s17_StringProcessing14AnyRegexOutputVMn", referenced from: _symbolic _____y______GSg 17_StringProcessing5RegexV5MatchV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) _symbolic _____y_____G 17_StringProcessing5RegexV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) _symbolic _____y______G 17_StringProcessing5RegexV5MatchV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) "_$s17_StringProcessing5RegexV10firstMatch2inAC0E0Vyx_GSgSS_tKF", referenced from: _$s8UnityAds19GatewayHashProviderC4hash3forSS10Foundation3URLV_tFTf4nd_n in UnityAds(UnityAds-arm64-master.o) "_$s17_StringProcessing5RegexV5MatchVMn", referenced from: _symbolic _____y______GSg 17_StringProcessing5RegexV5MatchV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) _symbolic _____y______G 17_StringProcessing5RegexV5MatchV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) "_$s17_StringProcessing5RegexVA2A03AnyC6OutputVRszlEyACyAEGSSKcfC", referenced from: _$s8UnityAds19GatewayHashProviderC4hash3forSS10Foundation3URLV_tFTf4nd_n in UnityAds(UnityAds-arm64-master.o) "_$s17_StringProcessing5RegexVMn", referenced from: _symbolic _____y_____G 17_StringProcessing5RegexV AA03AnyC6OutputV in UnityAds(UnityAds-arm64-master.o) "_$s18BooleanLiteralTypes013ExpressibleByaB0PTl", referenced from: FantasyFighterIos C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_17.5\17.5.8020\targets\Xamarin.Shared.Sdk.targets 1641

Steps to Reproduce

built an Ios binding library with xcframework
use binding library in your ios project
use remote M2 chip mac to build your project

Did you find any workaround?

No

Build logs

CentralNode_devenv_PID=25024_x64_BuildManager_Default.zip

@akghasemi akghasemi added the binding-projects Issue or PR that affects binding projects label Aug 28, 2024
@rolfbjarne
Copy link
Member

Can you try adding this to your main csproj:

<PropertyGroup>
    <LinkWithSwiftSystemLibraries>true</LinkWithSwiftSystemLibraries>
</PropertyGroup>

That might only fix some of the errors, I think this will still cause problems:

ld: warning: Could not find or use auto-linked framework 'UnitySwiftProtobuf'

you need to bind and link with the UnitySwiftProtobuf framework as well.

Can you try that and see if it works? If not, please upload an updated binlog.

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Aug 30, 2024
@rolfbjarne rolfbjarne added this to the Future milestone Aug 30, 2024
@akghasemi
Copy link
Author

I tried the LinkWithSwiftSystemLibraries to my project which didn't help and I couldn't find UnitySwiftProtobuf framework anywhere in my mac or in the internet. it seems that is an internal library that has been referenced in UnityAds and only is available inside the UnityAds binary.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Aug 31, 2024
@rolfbjarne
Copy link
Member

I tried the LinkWithSwiftSystemLibraries to my project which didn't help

Can you get an updated binlog with this property set?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Sep 2, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 2, 2024
@akghasemi
Copy link
Author

Hi ,basically I get the same error but here are the updated binlog. I also want to share my csproj file.

 <Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0-ios17.5</TargetFramework>
		<Nullable>enable</Nullable>
		<ImplicitUsings>true</ImplicitUsings>
		<IsBindingProject>true</IsBindingProject>
	</PropertyGroup>
	<PropertyGroup>
		<PackageId>Ghasemi.UnityAds.iOS</PackageId>
		<Version>1.0.10</Version>
		<Authors>Test User</Authors>
		<Company></Company>
		<Description>A binding library for uintyAds.xcframework</Description>
		<PackageTags>xamarin;binding;iOS</PackageTags>
		<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
	</PropertyGroup>
	<PropertyGroup>
		<EnableSwiftSupport>true</EnableSwiftSupport>
	</PropertyGroup>

	<ItemGroup>
		<NativeReference Include="UnityAds.xcframework">
			<Kind>Framework</Kind>
			<ForceLoad>True</ForceLoad>
			<LinkerFlags>-all_load</LinkerFlags>
			<LinkWithSwiftSystemLibraries>true</LinkWithSwiftSystemLibraries>
		</NativeReference>

		<None Update="UnityAds.xcframework/**" Pack="true" PackagePath="runtimes/ios/native"/>

		<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
		<ObjcBindingCoreSource Include="StructsAndEnums.cs" />
	</ItemGroup>
</Project>

CentralNode_devenv_PID=34288_x64_BuildManager_Default.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Sep 2, 2024
@rolfbjarne
Copy link
Member

I tried the LinkWithSwiftSystemLibraries to my project which didn't help and I couldn't find UnitySwiftProtobuf framework anywhere in my mac or in the internet. it seems that is an internal library that has been referenced in UnityAds and only is available inside the UnityAds binary.

Can you try adding the LinkWithSwiftSystemLibraries=true property to the main csproj (as a top-level property) and see if that makes a difference? If it still fails, please provide an updated binlog.

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Sep 4, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 4, 2024
@akghasemi
Copy link
Author

akghasemi commented Sep 4, 2024

Hi, I have added the LinkWithSwiftSystemLibraries=true directly under element in my main csproj file, it seems the error has changed. I also added updated binlog.

Error (active)		clang++ exited with code 1:
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_UADSBannerDelegate", referenced from:
     -exported_symbol[s_list] command line option
  "_OBJC_CLASS_$_UnityAdsInitializationDelegate", referenced from:
     -exported_symbol[s_list] command line option
  "_OBJC_CLASS_$_UnityAdsIos", referenced from:
     -exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)	FantasyFighterIos	C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_17.5\17.5.8020\targets\Xamarin.Shared.Sdk.targets	1641	
`

CentralNode_devenv_PID=33504_x64_BuildManager_Default.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Sep 4, 2024
@rolfbjarne
Copy link
Member

Can you show your ApiDefinition.cs file as well?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Sep 6, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 6, 2024
@akghasemi
Copy link
Author

sure, here it is the ApiDefinition.cs ,but I haven't completed it yet
`

[BaseType(typeof(NSObject))]
interface UnityAdsIos
{
    // +(void)initialize:(NSString * _Nonnull)gameId testMode:(BOOL)testMode initializationDelegate:(nullable id<UnityAdsInitializationDelegate>)initializationDelegate;
    [Static]
    [Export("initialize:testMode:initializationDelegate:")]
    void Initialize(string gameId, bool testMode, UnityAdsInitializationDelegate initializationDelegate);

    // +(BOOL)isReady:(NSString * _Nonnull)placementId;
    [Static]
    [Export("isReady:")]
    bool IsReady(string placementId);

    // +(void)show:(UIViewController * _Nonnull)viewController placementId:(NSString * _Nonnull)placementId;
    [Static]
    [Export("show:placementId:")]
    void Show(UIViewController viewController, string placementId);

    [Static]
    [Export("loadBanner:placementId:bannerDelegate:")]
    void LoadBanner(UIViewController viewController, string placementId, UADSBannerDelegate bannerDelegate);

    [Static]
    [Export("showBanner:placementId:")]
    void ShowBanner(UIViewController viewController, string placementId);

    [Static]
    [Export("hideBanner")]
    void HideBanner();
}

[BaseType(typeof(NSObject))]
interface UnityAdsInitializationDelegate
{
    // -(void)initializationComplete;
    [Export("initializationComplete")]
    void InitializationComplete();

    // -(void)initializationFailed:(UnityAdsInitializationError)error withMessage:(NSString *)message;
    [Export("initializationFailed:withMessage:")]
    void InitializationFailed(UnityAdsInitializationError error, string message);
}


[BaseType(typeof(NSObject))]
interface UADSBannerDelegate
{
    // -(void)bannerViewDidLoad:(UADSBannerView * _Nonnull)bannerView;
    [Export("bannerViewDidLoad:")]
    void BannerViewDidLoad(UADSBannerView bannerView);

    // -(void)bannerView:(UADSBannerView * _Nonnull)bannerView didFailWithError:(UADSBannerError * _Nonnull)error;
    [Export("bannerView:didFailWithError:")]
    void BannerViewDidFail(UADSBannerView bannerView, NSError error);

    // -(void)bannerViewDidClick:(UADSBannerView * _Nonnull)bannerView;
    [Export("bannerViewDidClick:")]
    void BannerViewDidClick(UADSBannerView bannerView);

    // -(void)bannerViewDidLeaveApplication:(UADSBannerView * _Nonnull)bannerView;
    [Export("bannerViewDidLeaveApplication:")]
    void BannerViewDidLeaveApplication(UADSBannerView bannerView);
}

[BaseType(typeof(NSObject))]
interface UADSBannerView
{
    [Export("initWithPlacementId:size:")]
    IntPtr Constructor(string placementId, CGSize size);

    [Export("load")]
    void Load();

    [Export("delegate", ArgumentSemantic.Weak)]
    UADSBannerDelegate Delegate { get; set; }
}

[BaseType(typeof(NSError))]
interface UADSBannerError
{

}

`

@rolfbjarne rolfbjarne added the no-auto-reply For internal use label Sep 11, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 11, 2024
@akghasemi
Copy link
Author

I faced another issue with the binding library. the result that I said was only for simulator and the project works against simulator well but when I build against real ios device I get this error:

clang++ exited with code 1:
duplicate symbol '_mono_component_debugger_init' in:
    /Users/TestUser/Library/Caches/Xamarin/mtbs/builds/TestProjectIos/cb542bba51ca0de723831bcb2d7ab593e51056cad7217ea4196d88c41f31f9f9/C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.ios-arm64/8.0.8/runtimes/ios-arm64/native/libmono-component-debugger-static.a(debugger.c.o)

I tried several solutions including what is mentioned in #19115 and added following to my main project but it didn't help

<PropertyGroup Condition=" '$(Platform)' == 'iPhone' ">
    <MtouchExtraArgs>--linkskip=Mono.Component.Debugger --linkskip=Mono.Component.Diagnostics_Tracing --linkskip=Mono.Component.HotReload</MtouchExtraArgs>
</PropertyGroup>

and

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
	<MtouchLink>None</MtouchLink>
	<MtouchExtraArgs>-gcc_flags "-Xlinker -ld_classic"</MtouchExtraArgs>	
</PropertyGroup>

the strange thing is that when I remove the binding library from project then everything works normal.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Sep 13, 2024
@rolfbjarne
Copy link
Member

duplicate symbol '_mono_component_debugger_init' in:

That's really weird, and shouldn't happen.

Can you get an updated binlog that shows this error?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Sep 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 13, 2024
@akghasemi
Copy link
Author

Here it is an updated binlog
CentralNode_devenv_PID=22716_x64_BuildManager_Default.zip

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Sep 15, 2024
@rolfbjarne
Copy link
Member

rolfbjarne commented Sep 16, 2024

That's a bug in our code (filed as #21244).

However, it's triggered by this line in your native reference:

<LinkerFlags>-all_load</LinkerFlags>

Which shouldn't be needed if your native library is a (dynamic) framework, so could you please try to remove this linker flag to see if that helps?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated and removed need-attention An issue requires our attention/response labels Sep 16, 2024
@akghasemi
Copy link
Author

akghasemi commented Sep 19, 2024

I changed as you suggested now the build targeting the device works also, but the application crashes on startup in real device and works fine in simulator and visual studio reports nothing when it crashes. I am not sure if the problem is related to binding library itself.
I see this log in device log as error: kernel(Sandbox) Sandbox: FantasyFighterIos(2121) deny(1) sysctl-read kern.bootargs

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Sep 19, 2024
@rolfbjarne
Copy link
Member

I changed as you suggested now the build targeting the device works also, but the application crashes on startup in real device and works fine in simulator and visual studio reports nothing when it crashes. I am not sure if the problem is related to binding library itself. I see this log in device log as error: kernel(Sandbox) Sandbox: FantasyFighterIos(2121) deny(1) sysctl-read kern.bootargs

Can you see if there are any crash reports in Xcode (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#crash-reports)?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Sep 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Sep 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed this from the Future milestone Sep 30, 2024
@akghasemi
Copy link
Author

akghasemi commented Oct 6, 2024

Hi @rolfbjarne , sorry I was on vacation, I see this in the logs in xcode

{"app_name":"FantasyFighterIos","timestamp":"2024-10-06 20:48:11.00 +0200","app_version":"1","slice_uuid":"24e0704e-f032-368b-93cc-ba013c6d1f86","build_version":"1","platform":"0","bundleID":"Ghasemi.FantasyFighterIos","share_with_app_devs":"1","is_first_party":"0","bug_type":"309","os_version":"iPhone OS 17.6.1 (21G93)","roots_installed":"0","name":"FantasyFighterIos","incident_id":"6FBB6E64-7F01-4D4C-A865-742478477853"}
{
"uptime": 5400,
"procRole": "unknown",
"version": 2,
"userID": 501,
"deployVersion": 210,
"modelCode": "iPhone11,8",
"coalitionID": 530,
"osVersion": {
"isEmbedded": true,
"train": "iPhone OS 17.6.1",
"releaseType": "User",
"build": "21G93"
},
"captureTime": "2024-10-06 20:48:11.7095 +0200",
"codeSigningMonitor": 1,
"incident": "6FBB6E64-7F01-4D4C-A865-742478477853",
"pid": 730,
"cpuType": "ARM-64",
"roots_installed": 0,
"bug_type": "309",
"procLaunch": "2024-10-06 20:48:11.4667 +0200",
"procStartAbsTime": 130527144510,
"procExitAbsTime": 130532939504,
"procName": "FantasyFighterIos",
"procPath": "/private/var/containers/Bundle/Application/7840EA38-CE87-4DD5-998B-33875F00D584/FantasyFighterIos.app/FantasyFighterIos",
"bundleInfo": {
"CFBundleShortVersionString": "1",
"CFBundleVersion": "1",
"CFBundleIdentifier": "Ghasemi.FantasyFighterIos"
},
"storeInfo": {
"deviceIdentifierForVendor": "C370D161-7B29-418D-A4C6-5316697EAECE",
"thirdParty": true
},
"parentProc": "launchd",
"parentPid": 1,
"coalitionName": "Ghasemi.FantasyFighterIos",
"crashReporterKey": "d0e8d31fb117ce68688c0760475992a0ae7fb95f",
"wasUnlockedSinceBoot": 1,
"isLocked": 1,
"codeSigningID": "Ghasemi.FantasyFighterIos",
"codeSigningTeamID": "4C4638XV47",
"codeSigningFlags": 570434309,
"codeSigningValidationCategory": 3,
"codeSigningTrustLevel": 6,
"basebandVersion": "6.00.00",
"exception": {
"codes": "0x0000000000000000, 0x0000000000000000",
"rawCodes": [
0,
0
],
"type": "EXC_CRASH",
"signal": "SIGABRT"
},
"termination": {
"code": 1,
"flags": 518,
"namespace": "DYLD",
"indicator": "Library missing",
"details": [
"(terminated at launch; ignore backtrace)"
],
"reasons": [
"Library not loaded: @rpath/libswiftCore.dylib",
"Referenced from: <24E0704E-F032-368B-93CC-BA013C6D1F86> /Volumes/VOLUME/*/FantasyFighterIos.app/FantasyFighterIos",
"Reason: tried: '/private/var/containers/Bundle/Application/7840EA38-CE87-4DD5-998B-33875F00D584/FantasyFighterIos.app/Frameworks/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/7840EA38-CE87-4DD5-998B-33875F00D584/FantasyFighterIos.app/Frameworks/libswiftCore.dylib' (no such file)"
]
},
"sharedCache": {
"base": 6931087360,
"size": 3667132416,
"uuid": "a2ced6fa-740f-3012-bd8a-7507e009df72"
},
"legacyInfo": {
"threadHighlighted": 0
},
"trialInfo": {
"rollouts": [],
"experiments": []
},
"reportNotes": [
"_dyld_process_info_create failed with 1",
"Corpse is incomplete (_dyld_process_info_create failed with 1)",
"Backtraces may be be unvailable or truncated to only leaf frames, and the binary image list may not be available",
"thread_get_state(PAGEIN) returned 0x10000003: (ipc/send) invalid destination port",
"thread_get_state(EXCEPTION) returned 0x10000003: (ipc/send) invalid destination port",
"thread_get_state(FLAVOR) returned 0x10000003: (ipc/send) invalid destination port"
]
}

@rolfbjarne
Copy link
Member

Looks like the app requires Swift libraries:

Library not loaded: @rpath/libswiftCore.dylib
Referenced from: <24E0704E-F032-368B-93CC-BA013C6D1F86> /Volumes/VOLUME/*/FantasyFighterIos.app/FantasyFighterIos
Reason: tried: '/private/var/containers/Bundle/Application/7840EA38-CE87-4DD5-998B-33875F00D584/FantasyFighterIos.app/Frameworks/libswiftCore.dylib' (no such file), '/private/var/containers/Bundle/Application/7840EA38-CE87-4DD5-998B-33875F00D584/FantasyFighterIos.app/Frameworks/libswiftCore.dylib' (no such file)
(terminated at launch; ignore backtrace)

Try changing the value of the SupportedOSPlatformVersion in the main csproj from 11.2 to 12.2 (or higher), I believe that should fix it.

@akghasemi
Copy link
Author

Thanks everything works now, I will try to put the project in GitHub for the others

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-projects Issue or PR that affects binding projects need-info Waiting for more information before the bug can be investigated
Projects
None yet
Development

No branches or pull requests

2 participants