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

Open
akghasemi opened this issue Aug 28, 2024 · 19 comments
Open

ios binding library with xcframework fails to link #21142

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

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
{

}

`

@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 10, 2024
@rolfbjarne
Copy link
Member

how can I create a separate package that doesn't require linking every time I build the main project , I mean my binding library is separate project and I create nuget package from it, but in nuget package it seems not all files required by this library exist and every time i build the main project ,it tries to link this library with all its content, can I change this behavior?

I'm not entirely sure I understand what's going on.

Exactly what do you mean by "every time i build the main project ,it tries to link this library with all its content"?

@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 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
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