Add a dependency on xcframework inside a flutter plugin

Issue

I am developing a flutter plugin which internally depends on a IOS xcframework.

My podspec file for the flutter plugin(ios/flutter_plugin.podspec) looks something like this:

Pod::Spec.new do |s|
  s.name             = 'flutter_plugin'
  s.version          = '0.0.1'
  s.summary          = 'example plugin'
  s.description      = <<-DESC
A new flutter plugin project.
                       DESC
  s.homepage         = 'https://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'a' => 'abc@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.dependency 'Flutter'
  s.platform = :ios, '11.0'
  # Flutter.framework does not contain a i386 slice.
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
  s.swift_version = '5.0'
  s.preserve_paths = 'MyFramework.xcframework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework MyFramework' }
  s.vendored_frameworks = 'MyFramework.xcframework'
end

When i import the example project (example/Runner.xcworkspace) inside Xcode, i am able build and run the application correctly.
However, when i try to run the app from the command line using flutter run, i get the following errors:
error: module ‘MyFramework’ has no member named ‘someName’

Solution

I figured out the solution, i had to add this one line in my podspec file:

s.dependency 'MyFramework'

Answered By – user966123

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *