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

The bridge always wants to load a framework on iOS #1772

Closed
Berrysoft opened this issue Feb 22, 2024 · 8 comments · Fixed by #1773
Closed

The bridge always wants to load a framework on iOS #1772

Berrysoft opened this issue Feb 22, 2024 · 8 comments · Fixed by #1773
Labels
bug Something isn't working

Comments

@Berrysoft
Copy link
Contributor

Describe the bug

I'm trying to upgrade a frbv1 project to frbv2. The upgrade is successful on Android, but not iOS. With frbv1, the native lib is built as staticlib with a project generated by cargo-xcode. However, after upgrading to frbv2, the dart side always wants to load native.framework/native. I looked through the examples in this repo, but they all use cargokit. Is there a smooth upgrade path to still use the static lib without framework, or a way to change the xcode project to generate a dummy framework?

Steps to reproduce

The instructions here is interesting. Does dart_minimal really run well on iOS?

Logs

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'native.framework/native': dlopen(native.framework/native, 0x0001): tried: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRootnative.framework/native' (errno=2), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/native.framework/native' (errno=2), '/usr/lib/swift/native.framework/native' (errno=2, not in dyld cache), '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/native.framework/native' (errno=2), '/usr/lib/swift/native.framework/native' (errno=2, not in dyld cache), '/Users/berrysoft/Library/Developer<…>

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

@Berrysoft Berrysoft added the bug Something isn't working label Feb 22, 2024
Copy link

welcome bot commented Feb 22, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 22, 2024

Hi, one way is to customize how the library is loaded: https://cjycode.com/flutter_rust_bridge/guides/how-to/load-library

Another way is to use flutter_rust_bridge_codegen create/integrate to generate v2 scaffold in one command, and then move your code into that scaffold.

Does dart_minimal really run well on iOS?

Yes, this is guaranteed by running it on CI (all platforms are auto checked, as well as many other checks) ;)

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Feb 22, 2024
@Berrysoft
Copy link
Contributor Author

Berrysoft commented Feb 22, 2024

@fzyzcjy Thank you for your advice! However after I choose to load the library from the process, the bridge complains cannot find store_dart_post_cobject. I revert back the changes to use the dummy_method_to_enforce_bundling method, but the generated header by codegen doesn't include the declaration of drop_dart_object, get_dart_object, new_dart_opaque and store_dart_post_cobject. Did I missed some steps?

P.S. I now generate the header with full_dep: true

@Berrysoft
Copy link
Contributor Author

Or, where should I change the link args to make the linker always link the static lib so that I don't need the dummy method to enforce bundling?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 22, 2024

but the generated header by codegen doesn't include the declaration of drop_dart_object, get_dart_object, new_dart_opaque and store_dart_post_cobject.

Ok this seems to be a bug, because dummy_method_to_enforce_bundling is not used in the cargokit-based approach so I missed it - feel free to PR (looks like a good-first-issue)! I guess it is as simple as, editing

and make it something like func_names + EXTRA_EXTERN_FUNC_NAMES.

Before fixing it, maybe firstly try to manually add that few functions, and see whether it works.

EDIT: Seems that it is already generated https://github.com/fzyzcjy/flutter_rust_bridge/blob/cfd88621f77de211a9c214508b2dfcca29efd4e7/frb_example/pure_dart/frb_generated.h#L16432

Btw, if your library does not customize the build process, then directly using flutter_rust_bridge_codegen create/integrate may one of be the easiest way.

@Berrysoft
Copy link
Contributor Author

EDIT: Seems that it is already generated

The declaration is not generated:) I mean the signature void store_dart_post_cobject(DartPostCObjectFnType ptr); is not generated.

And by the way it seems that the other 3 methods are no longer needed.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 22, 2024

Oh looks reasonable!

P.S. Its declaration can be copied from

void store_dart_post_cobject(DartPostCObjectFnType ptr);
via a global search of the keyword

Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
2 participants