12

I am creating a Flutter plugin. But when I am trying to add a dependency to iOS part of the plugin I am not finding any proper guideline for this. I declared the dependency in the podspec file of my plugin. But the dependency is only available in the example/ios through Pod but I want access that dependency in my ios folder of my plugin. This is my podspec:

#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
  s.name             = 'comet_chat'
  s.version          = '0.0.1'
  s.summary          = 'A new Flutter plugin.'
  s.description      = <<-DESC
A new Flutter plugin.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.dependency 'CometChatPro', '1.4.0'

  s.ios.deployment_target = '10.0'
  s.preserve_paths = 'CometChatPro.framework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework CometChatPro' }
  s.vendored_frameworks = 'CometChatPro.framework'
end

I followed this issue but it was of no help. How to solve this issue? How can I get my dependency only for the plugin?

sagar suri
  • 4,351
  • 12
  • 59
  • 122

2 Answers2

0

There is no way to "only open the plugin's classes", and the dependencies you add in your podspec are only available to your plugin, unless explicitly made it public.

TL;DR

By design, your iOS Flutter plugin will always run when embedded in a Flutter application project. Also, there is a conflict in your podspec; it should never specify the same framework in both dependency and vendored_frameworks.

If you have a CometChatPro.framework folder, copy it in your plugin's ios/Libraries folder and declare its path in your podspec in vendored_frameworks. Personally, I've never used the dependency specifier but there is an example in the flutter-webrtc plugin's implementation.

Either way, the ios/Classes folder of your plugin does have access to the dependencies that you specify in your ios/plugin_name.podpsec file. It just doesn't "know it" when you edit your plugin in any editor other than Xcode (Visual Studio Code, Android Studio, etc).

To develop the Swift or Objective-C classes for your plugin's iOS implementation, you should :

  1. Open the example's Xcode workspace located at example/ios/Runner.xcworkspace.
  2. Edit your plugin's iOS classes by navigating in Xcode to Pods/Development Pods/plugin_name/../../ios/.symlinks/plugins/plugin_name/ios/Classes
  3. Build your project to fix any compiling errors.

If at this point you still don't have access to the framework in your plugin's iOS classes, it means that it wasn't properly setup by Cocoapods. In that case, you'll need to find which Xcode Build Setting is not properly set and then specify these Build Settings in your plugin's podspec, like so:

  s.xcconfig = { 
                'FRAMEWORK_SEARCH_PATHS' => ['${PODS_TARGET_SRCROOT}/Libraries'],
                'HEADER_SEARCH_PATHS' => ["${PODS_ROOT}/../.symlinks/plugins/plugin_name/ios/Libraries/CometChatPro.framework/Headers"
               }

This explicitly adds the framework to your plugin target's FRAMEWORK_SEARCH_PATHS, and the framework's Headers path to the HEADER_SEARCH_PATH.

When linking vendored_frameworks, you want to make sure that Cocoapods did successfully embed the framework, and that you are building for the right architectures.

mrcendre
  • 1,053
  • 2
  • 15
  • 28
0

enter image description here

  • In your Flutter plugin open .podspec file and add the required dependency as show below.

For your reference

  • In my flutter plugin, I have added AzureCommunicationCommon, AzureCommunicationChat package with the required version
  • Also make sure to take care of s.pod_target_xcconfig
Rakesh R
  • 695
  • 7
  • 18