Skip to content

Plugins cannot be imported as modules in iOS platform code #1258

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! 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:

  1. flutter create test_create_app
  2. Add any flutterfire plugin with iOS platform code to the pubspec, like cloud_firestore.
dependencies:
  flutter:
    sdk: flutter
  cloud_firestore:
  1. In generated ios/Podfile remove use_frameworks!
  2. flutter build ios
  3. Build.

Screen Shot 2019-10-15 at 6 35 58 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 cloud_firestore.
dependencies:
  flutter:
    sdk: flutter
  cloud_firestore:
  1. flutter build ios
  2. In AppDelegate.m add @import cloud_firestore; at the top.
  3. Build.

Screen Shot 2019-10-15 at 6 45 40 PM

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions