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!
could also be removed from the generated app Podfile.
Flutter's CocoaPods minimum version is 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 first-party plugin with iOS platform code to the pubspec, like device_info.
dependencies:
flutter:
sdk: flutter
device_info: 0.4.0+2
- In generated
ios/Podfile
removeuse_frameworks!
flutter build ios
- In AppDelegate.swift add
import device_info
at the top. - 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 device_info.
dependencies:
flutter:
sdk: flutter
device_info: 0.4.0+2
flutter build ios
- In AppDelegate.m add
@import device_info;
at the top. - Build.
Proposal
- Add
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
to plugin podspec template - Migrate all first-party plugins to the new podspec and add import tests to all first-party iOS examples
- android_alarm_manager
- android_intent
- battery
- camera
- connectivity
- device_info
- google_maps_flutter
- google_sign_in
- image_picker
- in_app_purchase
- instrumentation_adapter
- local_auth
- package_info
- path_provider
- quick_actions
- sensors
- share
- shared_preferences
- url_launcher
- video_player
- webview_flutter
- cloud_firestore
- cloud_functions
- firebase_admob
- firebase_analytics
- firebase_auth
- firebase_core
- firebase_crashlytics
- firebase_database
- firebase_dynamic_links
- firebase_in_app_messaging
- firebase_messaging
- firebase_ml_vision
- firebase_performance
- firebase_remote_config
- firebase_storage
- Add migration tooling for existing plugins (?)
See also
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
#40289