I’m working on an iOS plugin for Flutter and need to include x.framework
with Mach-O 64-bit bundle arm64
binary type (so, it could be loaded by an app in the runtime) rather than Mach-O 64-bit dynamically linked shared library arm64
.
The framework is added to .podspec
via s.ios.vendored_frameworks
.
Flutter is linking the framework with -framework x
arg which gives an error:
Error (Xcode): Unsupported mach-o filetype (only MH_OBJECT and MH_DYLIB can be linked) in '/project_path/build/ios/Release-iphoneos/XCFrameworkIntermediates/plugin/x.framework/x'
Is there any way to exclude that framework from linking though the framework itself is included in the resulting app bundle?
2
Answers
you’ll need to prevent Xcode from attempting to link the framework while still including it in the app bundle for runtime loading.
To prevent Xcode from linking the framework but still include it in the app bundle, you can use the EXCLUDED_SOURCE_FILE_NAMES build setting in your .podspec file.
In your .podspec file, under the s.ios.vendored_frameworks section, add the following to exclude the actual framework binary from being linked:
To ensure that the framework is still included in the app bundle for runtime loading, you can specify s.preserve_paths in your .podspec:
Since the framework is a Mach-O bundle (MH_BUNDLE), you will need to load it dynamically at runtime in your iOS code. You can use NSBundle to load the framework manually when your app runs:
Make sure that your .podspec file includes other relevant settings for vendoring the framework:
You don’t need to specify EXCLUDED_SOURCE_FILE_NAMES. The s.exclude_files directive automatically handles excluding the files from being linked. Double-check the path to make sure it points directly to the Mach-O binary within the framework (e.g., path/to/x.framework/x).
If you’re using .xcframeworks, the paths may differ because .xcframeworks have separate folders for different architectures. For example:
You can get detailed logs during pod installation by running "pod install –verbose"