Skip to content

Support clang modules in plugins #41007

Closed
@jmagman

Description

@jmagman

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:

  1. flutter create test_create_app
  2. 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
  1. In generated ios/Podfile remove use_frameworks!
  2. flutter build ios
  3. In AppDelegate.swift add import device_info at the top.
  4. Build.

Screen Shot 2019-09-20 at 3 52 10 PM

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:

  1. flutter create -i objc test_create_app
  2. Add device_info.
dependencies:
  flutter:
    sdk: flutter
  device_info: 0.4.0+2
  1. flutter build ios
  2. In AppDelegate.m add @import device_info; at the top.
  3. Build.

Screen Shot 2019-09-20 at 3 38 02 PM

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

Metadata

Metadata

Assignees

Labels

a: existing-appsIntegration with existing apps via the add-to-app flowp: toolingAffects the flutter_plugin_tools packageplatform-iosiOS applications specificallytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions