Description
Background
Flutter plugins are added to Flutter apps with CocoaPods, but modules are not currently generated (assuming the current plugin template) when the plugin is created as a library instead of a framework.
From CocoaPods 0.36 release blog:
With this release, we initially allow you to use both in combination with CocoaPods. You can make CocoaPods integrate to your project via frameworks instead of static libraries by specifying use_frameworks!. If that's not present, you won't be able to integrate dependencies, if you depend on a pod which includes Swift source code. This is an all or nothing approach per integrated targets, because we can't ensure to properly build frameworks, whose transitive dependencies are static libraries. This release goes along with probably one of the most drastic changes of the whole project, which includes CocoaPods itself, but also required similar changes to Xcodeproj as well.
However as of CocoaPods 1.5.0 Swift apps do not need to generate pods as frameworks if all the pods generate modules, and use_frameworks!
is no longer required.
For add-to-app, workarounds/hacks in the Xcode project and Podfile cannot be automatically applied since flutter
does not generate or own either.
If all plugins created modules correctly, use_frameworks!
may theoretically also be removed from the generated app Podfile.
Flutter's CocoaPods minimum version is currently 1.6.0.
Issues
Objective-C plugins cannot be imported into Swift apps as libraries
Steps to reproduce:
flutter create test_create_app
- Add any flutterfire plugin with iOS platform code to the pubspec, like cloud_firestore.
dependencies:
flutter:
sdk: flutter
cloud_firestore:
- In generated
ios/Podfile
removeuse_frameworks!
flutter build ios
- Build.
Objective-C plugins can't be module imported (@import
) into Objective-C apps
Objective-C projects cannot use module imports. This means so @import
syntax, and #import <Plugin/Plugin.h>
imports do not automatically translate to a module import.
Steps to reproduce:
flutter create -i objc test_create_app
- Add cloud_firestore.
dependencies:
flutter:
sdk: flutter
cloud_firestore:
flutter build ios
- In AppDelegate.m add
@import cloud_firestore;
at the top. - Build.
Proposal
Add s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
to all podspecs that can define modules.
Example: flutter/plugins#2175
See also
flutter/flutter#41007
https://blog.cocoapods.org/CocoaPods-0.36/ <-- More complete description of the issues with frameworks/libraries
http://blog.cocoapods.org/CocoaPods-1.5.0/
https://clang.llvm.org/docs/Modules.html
flutter/flutter#40289