Importing IOS SDK libraries to a Flutter Plugin

2,477

You've mangled your Podspec file. There should only be one section starting Pod::Spec.new do |s|.... If you want to try the approach in the linked Github issue, your Podspec file should look like this:

Pod::Spec.new do |s|
  s.name             = 'plugin_name'
  s.version          = '0.0.1'
  s.summary          = 'A new flutter plugin project.'
  s.description      = <<-DESC
A new flutter plugin project.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => '[email protected]' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.ios.deployment_target = '9.0'
  s.preserve_paths = 'IOSFLUTTERSDK.framework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework IOSFLUTTERSDK' }
  s.vendored_frameworks = 'IOSFLUTTERSDK.framework'
  s.resource_bundle = { 'IOSFLUTTERSDK-Resources' => './*' }
end

However, I've tried this before with no success - I needed to link everything manually via Xcode by opening the project:

open example/ios/Runner.xcworksapce

Click on the "Runner" project at the top, and click on the "Build Phases" item on the right hand side (if "Build Phases" doesn't show, make sure the folder icon on the left is selected, and you've clicked the Runner Target in the middle panel, not the Runner Project).

enter image description here

Find the "Link Binary with Libraries" panel, and click the "+" button:

enter image description here

Select your .framework file and click "Done". Repeat the same under "Embed Frameworks".

I'm not 100% sure, but I think you can do the same under "Copy Bundle Resources".

Share:
2,477
Hussain Alkhars
Author by

Hussain Alkhars

Updated on December 12, 2022

Comments

  • Hussain Alkhars
    Hussain Alkhars over 1 year

    Summary: I am building a Flutter Plugin to be used for multiple projects I am developing. I have no experience writing custom platform-specific code.

    I am having trouble importing SDK library for IOS *.Framework and *-Resources.bundle to my plugin.

    I've tried to the solution for in https://github.com/flutter/flutter/issues/17978

    Also, I've tried cleaning and re-building the app but with no success and tried cleaning and re-building the example app but with no success and I receive the below error:

    *.podspec:

    Pod::Spec.new do |s|
      s.name             = 'plugin_name'
      s.version          = '0.0.1'
      s.summary          = 'A new flutter plugin project.'
      s.description      = <<-DESC
    A new flutter plugin project.
                           DESC
      s.homepage         = 'http://example.com'
      s.license          = { :file => '../LICENSE' }
      s.author           = { 'Your Company' => '[email protected]' }
      s.source           = { :path => '.' }
      s.source_files = 'Classes/**/*'
      s.public_header_files = 'Classes/**/*.h'
      s.dependency 'Flutter'
    
      s.ios.deployment_target = '9.0'
    end
    
    
    Pod::Spec.new do |spec|
      spec.name         = "plugin_name"
      spec.version      = "2.3.7"
      spec.summary      = "SDK"
      spec.homepage     = "https://hkhars.com"
      spec.author       = "Hussain Alkhars"
      spec.license          = { :file => '../LICENSE' }
      spec.source           = { :path => '.' }
      spec.ios.deployment_target  = '9.0'
      spec.preserve_paths = 'IOSFLUTTERSDK.framework'
      spec.xcconfig = { 'OTHER_LDFLAGS' => '-framework IOSFLUTTERSDK' }
      spec.vendored_frameworks = 'IOSFLUTTERSDK.framework'
      spec.public_header_files = "IOSFLUTTERSDK.framework/Headers/*.h"
      spec.resource_bundle = { 'IOSFLUTTERSDK-Resources' => './*' }
    end
    

    Error when trying to build with flutter build ios --no-codesign

    fatal error: 'plugin_name/PluginNamePlugin.h' file not found
        #import <plugin_name/PluginNamePlugin.h>```