Desdaemon / flutter_rust_bridge_template

Template for Flutter + Rust integration with flutter_rust_bridge.
https://desdaemon.github.io/flutter_rust_bridge_template/
Apache License 2.0
120 stars 63 forks source link

Build failing on iOS. Missing static library dependency #26

Closed trueb2 closed 1 year ago

trueb2 commented 1 year ago

I ran into an issue that I may have missed in the documentation but think are probably misconfigured. You would get errors like these since the library isn't built or linked.

Error (Xcode): Undefined symbol: _free_WireSyncReturnStruct
Error (Xcode): Undefined symbol: _store_dart_post_cobject
Error (Xcode): Undefined symbol: _wire_platform
Error (Xcode): Undefined symbol: _wire_rust_release_mode

The native framework from cargo-xcode that is in the template was identified via absolute path. I had to change that to a relative path manaully in xcode.

The other issue I had was that the Runner project did not depend on native. I manually added the native framework to Runner, then the build worked.

The last thing that I noticed were warnings about compiling for the right version of iOS, so I set deployment targets manually on native and Runner. I think there was a mismatch in the lipo defaults and Flutter AppFrameworkInfo default.

Object file (/Users/jwtrueb/Library/Developer/Xcode/DerivedData/Runner-axbaqoiwfycklwexmujahyblberb/Build/Products/Debug-iphoneos/libnative_static.a(libc-dcc407e75e762ce3.libc.7c476fd4-cgu.5.rcgu.o)) was built for newer iOS version (16.0) than being linked (11.0)

Here are some screenshots on where to look in Xcode.

Screen Shot 2022-11-01 at 9 31 44 AM Screen Shot 2022-11-01 at 9 30 57 AM

All good now! 🎉 Thanks for the template!

trueb2 commented 1 year ago

I ran into a couple other issues related to inconsistent iOS builds. The number one issue is that all builds stopped working. The root cause was that the $(DERIVED_FILE_DIR) did not exist all the sudden after clean and build. Xcode just stopped making it for some reason. This statement is the one that blew up

if [ -f "$DEP_FILE_SRC" ]; then
    DEP_FILE_DST="${DERIVED_FILE_DIR}/${CARGO_XCODE_TARGET_ARCH}-${EXECUTABLE_NAME}.d"
    cp -f "$DEP_FILE_SRC" "$DEP_FILE_DST"
    echo >> "$DEP_FILE_DST" "$SCRIPT_OUTPUT_FILE_0: $BUILT_SRC"
fi

The native-staticlib framework depends on $DEP_FILE_DST, so I just added mkdir -p $(DERIVED_FILE_DIR) before the copy attempt. Idk why this stopped working for me.

The other issue I ran into was that the build scheme stopped using Debug and Release correctly (mix and matching flutter and cargo build scheme). If you click on Runner and edit scheme, you can change all of the categories (Analyze especially) to Release or Debug. Again, idk why this changed at some point in using Xcode.

Stuff works again now, I added some echos to make it a little easier to figure out why xcode stopped building the same as before. The only thing that was really different was the lack of a $DERIVED_FILE_DIR.

Screen Shot 2022-11-08 at 5 51 40 PM
github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has no activity recently. Please remove the 'stale' label, or comment if the issue persists.