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 - Crash when app launches #21546

Open
jmpdi opened this issue Oct 29, 2024 · 7 comments · May be fixed by #21593
Open

iOS binding library - Crash when app launches #21546

jmpdi opened this issue Oct 29, 2024 · 7 comments · May be fixed by #21593
Labels
binding-projects Issue or PR that affects binding projects
Milestone

Comments

@jmpdi
Copy link

jmpdi commented Oct 29, 2024

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

JetBrains Rider 2024.2.7, .NET workload ios 18.0.8303/8.0.100, Xcode 16.0, iPhone 11 Pro iOS 17.7

Description

I'm trying to bind Braintree SDK for iOS v6.23.3.

The binding and app build successfully, but the app crashes at the launch screen. I'm testing on a physical device (iPhone 11 Pro, iOS 17.7). I haven't tried it in the simulator.

This repo demonstrates the problem. Build logs attached. Console log of the crash attached.

The crash is related to particular Braintree APIs. When I exclude the problematic APIs, the app launches successfully. I've added four "#define STARTUP_CRASH..." statements to the top of ApiDefinitions to isolate the problematic APIs. If I comment out all four of those "#define" statements, the app launches successfully. But if one or more are uncommented, the app will crash at launch.

The problematic APIs all relate to the BTPaymentMethodNonce type within BraintreeCore.xcframework. They either inherit from that type or utilize a descendent of that type.

Also, I see this warning in the build:

warning MT7091: The framework PPRiskMagnes.framework is a framework of static libraries, and will not be copied to the app.

If I change the NativeReference for that framework to "Static", I get a linker error during the build.

Any advice/insight is appreciated. Thanks.

Steps to Reproduce

  1. Download this repo.
  2. Build solution.
  3. Install Sample app on iOS device.
  4. Observe Sample app crash at launch screen.

Did you find any workaround?

No workaround.

Build logs

MSBuild_Log_Startup_Crash_241029.zip

Console_Log_Startup_Crash_241029.txt

@jmpdi jmpdi added the binding-projects Issue or PR that affects binding projects label Oct 29, 2024
@rolfbjarne
Copy link
Member

This is interesting, I can reproduce the crash.

It happens very early on, when we load the Objective-C types we know about, in fact it's our own generated Objective-C code that crashes, something equivalent

handle = [_TtC13BraintreeCore20BTPaymentMethodNonce class];

Would you happen to know if there's an Xcode sample project somewhere that exercises the Objective-C version of the API you want to bind?

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

jmpdi commented Oct 31, 2024

@rolfbjarne - Thanks for investigating this!

I searched for a sample project that uses the Objective-C APIs, but I didn't find anything.

I also asked the Braintree team about it. They don't have an Objective-C sample, but do say the SDK is compatible with Objective-C. See braintree/braintree_ios#1450 (comment)

Are there any other options to isolate/debug the problem?

Thanks again!

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

I'll have a look next week and see what I can figure out.

rolfbjarne added a commit that referenced this issue Nov 7, 2024
TODO:

* Clean up PR.
* Improve description.

Fixes #21546.
@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix and removed need-attention An issue requires our attention/response binding-projects Issue or PR that affects binding projects labels Nov 7, 2024
@rolfbjarne
Copy link
Member

I've figured out the problem, and a fix is in progress.

In the meantime, you can add this to your csproj as a workaround:

<PropertyGroup>
    <Registrar>dynamic</Registrar>
</PropertyGroup>

@rolfbjarne rolfbjarne added binding-projects Issue or PR that affects binding projects and removed bug If an issue is a bug or a pull request a bug fix labels Nov 7, 2024
@rolfbjarne
Copy link
Member

The problem is that the classes causing problems are stub classes, and we don't handle stub classes correctly (we've never run into them before):

@jmpdi
Copy link
Author

jmpdi commented Nov 8, 2024

@rolfbjarne -- Thank you! With your workaround, the startup crash is gone and I can access the Braintree APIs from my iOS app. I appreciate your help with this and I'm looking forward to the full fix. Thanks again!

rolfbjarne added a commit that referenced this issue Dec 10, 2024
TODO:

* Clean up PR.
* Improve description.

Fixes #21546.
rolfbjarne added a commit that referenced this issue Dec 12, 2024
TODO:

* Clean up PR.
* Improve description.

Fixes #21546.
@rolfbjarne
Copy link
Member

Once this fix has been released, the api definitions for these classes will have to be modified like this - the BaseType attribute needs to set "IsStubClass = true":

[BaseType (typeof (SwiftClass), IsStubClass = true)]

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants