skip to Main Content

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


  1. 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:

    s.exclude_files = "path/to/x.framework/x"

    To ensure that the framework is still included in the app bundle for runtime loading, you can specify s.preserve_paths in your .podspec:

    s.preserve_paths = "path/to/x.framework"

    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:

    NSString *frameworkPath = [[NSBundle mainBundle] pathForResource:@"x" ofType:@"framework"];
    NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath];
    
    if ([frameworkBundle load]) {
        NSLog(@"Successfully loaded the x framework.");
    } else {
        NSLog(@"Failed to load the x framework.");
    }

    Make sure that your .podspec file includes other relevant settings for vendoring the framework:

    s.ios.vendored_frameworks = "path/to/x.framework"
    Login or Signup to reply.
  2. 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:

    s.ios.vendored_frameworks = 'path/to/x.xcframework'
    s.exclude_files = 'path/to/x.xcframework/ios-arm64/x.framework/x'

    You can get detailed logs during pod installation by running "pod install –verbose"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search