flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond

Home Page:https://flutter.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Friction adding swift plugin to objective-c project

xster opened this issue · comments

commented

flutter create a non-swift project

In pubspec.yaml, add a swift plugin such as flutter_iap.

  1. flutter run warns about use_frameworks! from pod install. Easy to resolve so far.
  2. Building gives The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor. error.
    Seems like swift pod developers need to specify
    s.pod_target_xcconfig = { 'SWIFT_VERSION' => <a version above 2.3 for it to work with Xcode 9> }
    in their podspec. Added temporary hack in Podfile with
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.2'
    end
  end
end

and re-pod install
3.

#import "Headers/flutter_iap-umbrella.h"
            ^
   .../ios/Pods/Target Support Files/flutter_iap/flutter_iap-umbrella.h:13:9: error: include of non-modular header inside framework module 'flutter_iap': '.../.pub-cache/hosted/pub.dartlang.org/flutter_iap-1.0.1/ios/Classes/FlutterIapPlugin.h'

Add

pre_install do |installer|
  # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end

and

post_install do |installer|
  installer.pods_project.targets.each do |target|
    # workaround for https://github.com/CocoaPods/CocoaPods/issues/7463
    target.headers_build_phase.files.each do |file|
      file.settings = { 'ATTRIBUTES' => ['Public'] }
    end
  end
end

to make it work.

Wonder if we can add some automatic handling of swift plugins in the default objective-c project's Podfile

I tried these work arounds and it is still failing to build with the same error. Do I need to make any specific changes to the podfile that is being included or something too? I just did these in my app podfiles...

 <module-includes>:1:9: note: in file included from <module-includes>:1:
    #import "Headers/flutter_places_dialog-umbrella.h"
            ^
    /Users/ddb/git/mobile/flutter_fuse/ios/Pods/Target Support Files/flutter_places_dialog/flutter_places_dialog-umbrella.h:13:9: error: include of non-modular header inside framework module 'flutter_places_dialog': '/Users/ddb/git/flutter_places_dialog/ios/Classes/FlutterPlacesDialogPlugin.h'
    #import "FlutterPlacesDialogPlugin.h"

@pinkfish
Are you using cocoapods 1.5.0?

If so, try downgrading to 1.4.0. That's the only way I've been able to get it to work.
sudo gem install cocoapods -v 1.4.0
delete your Podfile.lock and Podfile dir in /ios and do a pod install

@dlutton @pinkfish We have been unable to make Cocoapods 1.4.0 work all the way through to app store archives, and we'll be supporting only Cocoapods 1.5.0 or later going forward.

With Cocoapods 1.5.0 and newest Flutter tooling (on master), all you should have to do is patch your Podfile as follows:

target 'Runner' do
  use_frameworks! # <--- add this
  ...
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '3.2' # <--- add this
    end
  end
end

Then delete ios/Podfile.lock and execute flutter run.

Filing issue that changing ios/Podfile does not cause flutter run to redo pod install #16734

@mravn-google Tried cocoapods 1.5.0 and it's failing with:

Xcode's output:
↳
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
    ld: warning: Auto-Linking library not found for -lswiftSwiftOnoneSupport
    ld: warning: Auto-Linking library not found for -lswiftCoreAudio
    ld: warning: Auto-Linking library not found for -lswiftCore
    ld: warning: Auto-Linking library not found for -lswiftQuartzCore
    ld: warning: Auto-Linking library not found for -lswiftCoreImage
    ld: warning: Auto-Linking library not found for -lswiftCoreGraphics
    ld: warning: Auto-Linking library not found for -lswiftAVFoundation
    ld: warning: Auto-Linking library not found for -lswiftCoreMedia
    ld: warning: Auto-Linking library not found for -lswiftDispatch
    ld: warning: Auto-Linking library not found for -lswiftObjectiveC
    ld: warning: Auto-Linking library not found for -lswiftCoreFoundation
    ld: warning: Auto-Linking library not found for -lswiftUIKit
    ld: warning: Auto-Linking library not found for -lswiftDarwin
    ld: warning: Auto-Linking library not found for -lswiftMetal
    ld: warning: Auto-Linking library not found for -lswiftsimd
    ld: warning: Auto-Linking library not found for -lswiftFoundation
    Undefined symbols for architecture x86_64:
[✓] Flutter (Channel master, v0.3.1-pre.35, on Mac OS X 10.13.3 17D102, locale en-US)
    • Flutter version 0.3.1-pre.35 at /Users/dlutton/development/flutter
    • Framework revision 7b163c7c0b (4 hours ago), 2018-04-18 20:31:45 -0700
    • Engine revision 3cc8d82895
    • Dart version 2.0.0-dev.48.0.flutter-fe606f890b

[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.3, Build version 9E145
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.0

@dlutton Would you be able to share your pubspec.yaml and ios/Podfile?

@mravn-google
Maybe it's my flutter_tts plugin I wrote in swift that's failing. It worked with cocoapods 1.4.

Podfile:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) { |line|
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
      plugin = line.split(pattern=separator)
      if plugin.length == 2
        podname = plugin[0].strip()
        path = plugin[1].strip()
        podpath = File.expand_path("#{path}", file_abs_path)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end

target 'Runner' do
  use_frameworks!

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf Pods/.symlinks')
  system('mkdir -p Pods/.symlinks/plugins')

  # Flutter Pods
  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
  if generated_xcode_build_settings.empty?
    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
  end
  generated_xcode_build_settings.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join('Pods', '.symlinks', 'flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
    end
  }

  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join('Pods', '.symlinks', 'plugins', p[:name])
    File.symlink(p[:path], symlink)
    pod p[:name], :path => File.join(symlink, 'ios')
  }
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '3.2'
    end
  end
end

pubspec.yaml

name: fof
description: A new Flutter project.

dependencies:
  flutter:
    sdk: flutter
  connectivity:
  flutter_tts:
  share: "^0.3.1"

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  assets:
    - assets/failure.webp
    - assets/fortune.webp
    - assets/LaunchImage.png

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: Lato
      fonts:
        - asset: fonts/Lato-Regular.ttf
          weight: 400
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies, 
  # see https://flutter.io/custom-fonts/#from-packages

The flutter_tts plugin works fine when included in a Flutter project created using -i swift.

Adding an empty Swift file to your Flutter iOS project in Xcode and accepting to add bridging header also works.

Okay I’ll try that out thank you

@mravn-google I confirmed it's working with cocoapods 1.5.0. Thank you sir

@mravn-google can you explain how to

Adding an empty Swift file to your Flutter iOS project in Xcode and accepting to add bridging header also works.

Where am I creating this file and what is a bridging header?

@goodis0 Did you find an answer to this? Trying to add a pub package to a project I created with Flutter: New Project in Visual Studio Code and it's failing due to SWIFT_VERSION error being discussed.

Can confirm that @mravn-google provided a simple and effective fix #16049 (comment)

One of our customers tried @mravn-google's and @xster's workarounds and is still seeing errors:

/Users/xiao/projects/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-2.0.0/ios/Classes/strategies/AudioVideoPermissionStrategy.swift:14:80: error: type 'AVMediaType' (aka 'NSString') has no member 'video'
                return AudioVideoPermissionStrategy.getPermissionStatus(mediaType: AVMediaType.video)
                                                                                   ^~~~~~~~~~~ ~~~~~
    /Users/xiao/projects/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-2.0.0/ios/Classes/strategies/AudioVideoPermissionStrategy.swift:16:80: error: type 'AVMediaType' (aka 'NSString') has no member 'audio'
                return AudioVideoPermissionStrategy.getPermissionStatus(mediaType: AVMediaType.audio)

Any other suggestions for workarounds?
cc @hukid

I also hit the same issue @efortuna mentioned after applying @mravn-google's workaround, but fixed it by choosing a later Swift version in the Podfile:

      config.build_settings['SWIFT_VERSION'] = '4.0' # <--- instead of 3.2

This enabled me to successfully add the geolocator package to an Objective-C project. Can you try this, @hukid?

@timsneath I've tried with config.build_settings['SWIFT_VERSION'] = '4.0' and it is still not working because I had to disable # use_frameworks!. It was needed to be disabled for firebase messaging library. It is a known issue #9694.

Btw to describe what is not working, I try to use a plugin written in swift, https://pub.dartlang.org/packages/permission_handler but when I include it to my pubspec file, it cannot run on ios because it couldn't find the header files.

Error launching application on iPhone.
    ** BUILD FAILED **
    
Xcode's output:
↳
    /Users/gunhansancar/development/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-2.1.0/ios/Classes/PermissionHandlerPlugin.m:2:9: fatal error: 'permission_handler/permission_handler-Swift.h' file not found
    #import <permission_handler/permission_handler-Swift.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    /Users/gunhansancar/development/flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-2.1.0/ios/Classes/PermissionHandlerPlugin.m:2:9: fatal error: 'permission_handler/permission_handler-Swift.h' file not found
    #import <permission_handler/permission_handler-Swift.h>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.

Any updates on this? I am having the same issues with including both a Swift plugin (get_version) and the Google Maps map_view plugin. I can get one of the other to work but not both ... Rather frustrating... On iOS of course.. seems fine on Android..

I was also trying to get the 'geolocator' package to work in an Flutter iOS app. I did the @timsneath Podfile tweak above, but I figured why not go to the latest, 4.2? Well, that doesn't work, since some UIKit type is deprecated at 4.2, so I went back to 4.0, and everything works great. But does this mean use of this package will break as we use later Swift versions? I'm at Xcode 10.1, Build version 10B61, ios-deploy 1.9.2, CocoaPods version 1.5.3. Thanks @timsneath for the tweak.

@dlutton @pinkfish We have been unable to make Cocoapods 1.4.0 work all the way through to app store archives, and we'll be supporting only Cocoapods 1.5.0 or later going forward.

With Cocoapods 1.5.0 and newest Flutter tooling (on master), all you should have to do is patch your Podfile as follows:

target 'Runner' do
  use_frameworks! # <--- add this
  ...
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '3.2' # <--- add this
    end
  end
end

Then delete ios/Podfile.lock and execute flutter run.

Filing issue that changing ios/Podfile does not cause flutter run to redo pod install #16734

This way is very effective,but it caused another problem in my project.
I have a local plugin and it import a local .framefork file,this is my plugin's podspec:
`
Pod::Spec.new do |s|

s.name             = 'tx_ugc'
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/**/*.h','Classes/**/*.m','Third/AFNetworking/**/*','Third/MBProgressHUD/**/*','Third/Masonry/**/*'
s.public_header_files = 'Classes/**/*.h'#,'TXLiteAVSDK_UGC.framework/Headers/*.h'
s.resources = ['Classes/demo/Record/VideoRecordConfigViewController.xib','Classes/demo/Record/VideoRecord.xcassets','Classes/demo/Common/Resource/**/*','Assets/Assets.xcassets']
s.dependency 'Flutter'

s.frameworks    = "Accelerate", "SystemConfiguration"
s.libraries     = "sqlite3", "c++"

s.vendored_frameworks = "TXLiteAVSDK_UGC.framework"
s.ios.deployment_target = '8.0'

s.default_subspec = "precompiled"

s.subspec "precompiled" do |ss|
    ss.preserve_paths         = "TXLiteAVSDK_UGC.framework/Headers/*.h"
    ss.xcconfig = { 'HEADER_SEARCH_PATHS' => "${PODS_ROOT}/Headers/Public/#{s.name}" }
end

end
`

My problem is, if I add "use_frameworks!" in my main project's Profile,I can't refer to the header file in TXLiteAVSDK_UGC.framework in a .h file,such as "import 'TXLiteAVSDK_UGC/TXVodplayer.h' ",but in .m file it works normally;

hao can I solve this problem?
can you help me?
thank you very much!

Just a note, as of Flutter stable (i.e. 1.0.0), any project created via flutter create still encounters this issue if you don't opt-in to Swift at get get-go.

For example, I tried to use package:device_id, and it took some Google-foo (and finding this issue) to get things to work.

Yeah, for what it's worth, I've advocated for this for a while (#21190). I know that we were deferring this at one point because of other template changes, but since those have themselves been deferred, we should review this again. Adding @mit-mit and @cbracken.

cc @csells, can you take this one?

@mit-mit Talking to the team now.

Should I recreate my project with the swift flag to avoid running into this issue? Not being able to mix plugins is a slight problem.

@dvaldivia, I was running into this issue today after I added the packages/flutter_photokit to my non-swift project where I also use other plugins.

In the end I could make it work combining @mravn-google's and @sjmcdowall's advices

target 'Runner' do
  use_frameworks! # <-- here
  ...
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '4.0' # <-- and this (3.2 and 4.2 didn't work for me)
    end
  end
end

No need to recreate the whole project.

@robbash this worked for me, however swift version is 4.2; 4.0 did not work. Cheers! 🍻

Any updates on this? I want to use permission_handler plugin and cannot build with any given version

@dotsoftware -- What have you tried so far? Did none of the above solutions work?

@sjmcdowall - Yesterday I tried another approach and finally managed to build on iOS.
Since setting the swift version and use_frameworks! did not work, I generated a whole new project from scratch using flutter create -i swift and copied my existing sources into that project. Then I reinstalled all pods and it worked.

This error was fixed on my machine by running $ rm -rf ios android && flutter create -i swift . and then restarting Android Studio.

Hi everyone, ive spent a decent amount of days trying to figure out how to get this audio player working and im starting to loose my mind a bit.. ive followed everyones advice here and many other forums and still see to end up with this error

Launching lib/main.dart on iPhone XR in debug mode...
CocoaPods' output:

Preparing
Analyzing dependencies
[!] The target Runner is declared twice for the project Runner.xcodeproj.
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer/analyzer.rb:196:in validate_podfile!' /usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer/analyzer.rb:73:in analyze'
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:243:in analyze' /usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:154:in block in resolve_dependencies'
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/user_interface.rb:64:in section' /usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:153:in resolve_dependencies'
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/installer.rb:116:in install!' /usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/command/install.rb:41:in run'
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/claide-1.0.2/lib/claide/command.rb:334:in run' /usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/lib/cocoapods/command.rb:52:in run'
/usr/local/Cellar/cocoapods/1.5.3/libexec/gems/cocoapods-1.5.3/bin/pod:55:in <top (required)>' /usr/local/Cellar/cocoapods/1.5.3/libexec/bin/pod:22:in load'
/usr/local/Cellar/cocoapods/1.5.3/libexec/bin/pod:22:in `

'
Error running pod install
Error launching application on iPhone XR.

To be honest be honest it would be amazing if the Flutter team made an official audio class for working with audio files. Recorder would be great to, but ya cant wait to get this stuff working any help would be amazing!

This workaround as of cocoapods 1.6.1 stops working. Had to downgrade to 1.5.0 to make it work again.

I've tried all of the workarounds mentioned here any other places, and have now come across a different error:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_GMSMarker", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapMarkerController.o)
  "_OBJC_CLASS_$_GMSMutablePath", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapPolylineController.o)
  "_OBJC_CLASS_$_GMSCameraPosition", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapController.o)
  "_OBJC_CLASS_$_GMSCameraUpdate", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapController.o)
  "_OBJC_CLASS_$_GMSCoordinateBounds", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapController.o)
  "_OBJC_CLASS_$_GMSMapView", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapController.o)
  "_OBJC_CLASS_$_GMSPolyline", referenced from:
      objc-class-ref in google_maps_flutter(GoogleMapPolylineController.o)
  "_kGMSMinZoomLevel", referenced from:
      _InterpretMapOptions in google_maps_flutter(GoogleMapController.o)
  "_kGMSMaxZoomLevel", referenced from:
      _InterpretMapOptions in google_maps_flutter(GoogleMapController.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is when trying to build an iOS app containing a Flutter module which uses Google Maps.

Has anyone encountered a similar error?

Can we hear from the flutter team if the 'recommended' setup supports swift plugins or not?
If yes, why does the new empty project fails to build for iOS as soon as you add a swift plugin in it?
If no, do you need to update the official tutorial at https://flutter.dev/docs/get-started/codelab?

Hi @duzenko, thanks for your note. It's true that there's more friction for adding Swift plug-ins than we'd like.

We're considering switching the default language for projects to Swift (and Kotlin on the Android side), which will help with this. There's an open issue at #21190 that discusses this, and now that Swift is ABI-stable and Kotlin is the recommended language from the Android team, it is increasingly feeling like time to make the change.

As I mentioned on that bug, you can run flutter create . in your Flutter app directory and it will repair the project, recreating any files that are missing. So if you already have a project created with Objective-C and Java, you can run:

flutter create . -i swift -a kotlin

to convert the host app to Kotlin and Swift.

I don't see anywhere on the tutorials you reference where we tell the reader to use Objective-C, but we'd certainly welcome pull requests that clarify this. Thanks for the good feedback!

Flutter modules don't have support for being created using swift, and always use objective-C. It would be great to add swift support to modules too.

@timsneath whilst the default settings are being discussed, would it possible to have the docs updated with a note to suggest that the iOS project is created in Swift and/or mention the known issue in consuming a Swift plugin within an Objective-C project? This would avoid developers running into the problem sooner and alleviate a bit of the burden where plugin maintainers get issues reported due to this issue as well

I don't see anywhere on the tutorials you reference where we tell the reader to use Objective-C, but we'd certainly welcome pull requests that clarify this. Thanks for the good feedback!

It's here: https://flutter.dev/docs/get-started/test-drive?tab=terminal#create-app
Specifically:

Use the flutter create command to create a new project:

 flutter create myapp
 cd myapp

Also running flutter create -h (using Flutter 1.5.4-hotfix.2 • channel stable) says this:

...
-i, --ios-language             [objc (default), swift]
-a, --android-language         [java (default), kotlin]
...

As I mentioned on that bug, you can run flutter create . in your Flutter app directory and it will repair the project, recreating any files that are missing. So if you already have a project created with Objective-C and Java, you can run:

flutter create . -i swift -a kotlin

@timsneath
I think it's

flutter create -i swift -a kotlin .

And it does not work. The same pod error.

Delete the ios folder and run below command, this will rebuild the project with swift integration
$ flutter create -i swift .

This will rebuild the project with swift integration

Thanks idurvesh. Excuse the novice question but can that be done in the androidstudioprojects folder directory where I have the project?

@AriCohen8 for the command to work, your working directory should be set to the location of your Flutter app (e.g. same location as the pubspec.yaml file). If I remember correctly, if you've made any changes to the files within the iOS project then it'll remove all them. I suspect most devs don't fall into that category though unless you've written some Objective-C code for things like platform channels (note: i'm assuming you created your Flutter app with the default settings that has the iOS app side in Objective-C)

@MaikuB thank you!

From #25676 (comment)

I was testing Swift plugins for add-to-app with both use_frameworks! (dynamic and static frameworks) and without (static libraries). I tested with flutter_photokit, CocoaPods 1.7.5 and Xcode 11 Seed 1.

As-is, only the existing Swift app succeeded when use_frameworks! was present. Without use_frameworks! I saw 'flutter_photokit/flutter_photokit-Swift.h' file not found. And the Objective-C host couldn't get past pod install:

[!] Unable to determine Swift version for the following pods:

- `flutter_photokit` does not specify a Swift version and none of the targets (`ScaryBugs`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.
use_frameworks! no use_frameworks!
Obj-C host [!] Unable to determine Swift version for the following pods: [!] Unable to determine Swift version for the following pods:
Swift host 'flutter_photokit/flutter_photokit-Swift.h' file not found

Then I tried adding s.swift_versions = ['4.0', '4.2', '5.0'] to the flutter_photokit.podspec. Now the Objective-C host builds.

use_frameworks! no use_frameworks!
Obj-C host 'flutter_photokit/flutter_photokit-Swift.h' file not found
Swift host 'flutter_photokit/flutter_photokit-Swift.h' file not found

Then I tried this __has_include hack. CocoaPods/CocoaPods#7594 (comment)
I updated https://github.com/kmorkos/flutter_photokit/blob/master/ios/Classes/FlutterPhotokitPlugin.m to:

#import "FlutterPhotokitPlugin.h"
#if __has_include("flutter_photokit-Swift.h")
#import "flutter_photokit-Swift.h"
#else
#import <flutter_photokit/flutter_photokit-Swift.h>
#endif

@implementation FlutterPhotokitPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  [SwiftFlutterPhotokitPlugin registerWithRegistrar:registrar];
}
@end

And that fixed Swift. Objective-C now complains:

Undefined symbol: protocol conformance descriptor for Swift.String : Swift.CVarArg in Foundation
Undefined symbol: Darwin._convertDarwinBooleanToBool(Darwin.DarwinBoolean) -> Swift.Bool
Undefined symbol: _swift_getWitnessTable
Undefined symbol: protocol descriptor for Swift.CVarArg
Undefined symbol: _swift_getExistentialTypeMetadata
Undefined symbol: _swift_getForeignTypeMetadata
Undefined symbol: _swift_projectBox
etc
use_frameworks! no use_frameworks!
Obj-C host Undefined symbol: protocol conformance descriptor for Swift.String : Swift.CVarArg in Foundation
Swift host

I am running Xcode 11 and I found this note https://stackoverflow.com/a/57126566 and added "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" to my app target's LIBRARY_SEARCH_PATHS and that gets me down to two undefined symbols:

Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements
Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility50

And now I'm in the bowels of Swift: https://github.com/apple/swift/blob/master/lib/IRGen/GenDecl.cpp#L454

So I added "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)" to my app target's LIBRARY_SEARCH_PATHS.

use_frameworks! no use_frameworks!
Obj-C host
Swift host

@zanderso should we consider reverting #38339 and keeping the default plugin language to ObjC until this is resolved?

Right now plugins that are created with the default template cannot be just used in ObjC flutter apps...

@amirh You're not really talking about reverting the whole of #38339, are you? You're just talking about reverting the default language for plug-ins to Objective-C, rather than new apps? The latter seems like a pretty major reversion.

Swift plug-ins in an Objective-C runner is a long-standing problem, see for example: #25676

But my hunch is that there are plenty of Swift plug-ins already on pub.dev -- this is not I think new to the default change. (Would be nice to confirm or refute my hunch, of course.)

Sorry I should have been more clear.
Yes - I'm talking about reverting the default language for new plugins to be ObjC.
I think that until Swift plugins are easy to use from all Flutter apps (ObjC/Swift apps) we should keep encouraging plugin authors to write iOS plugins using ObjC.

I'm hoping we can add s.swift_version = '5.0' to the Swift plugin template and it be mostly future-proof for apps running newer versions of Swift? https://swift.org/blog/abi-stability-and-more/

☝️ Blocked on #39921.

@jmagman's plan sounds like the best way forward.
If we can't get this fixed by next stable release I would suggest that we set the default language back to ObjC (for new plugins) until we fix the Swift issue.

More background for why #import <flutter_photokit/flutter_photokit-Swift.h> doesn't work for Swift libraries (no use_frameworks!):

https://paul-samuels.com/blog/2018/01/14/swift-static-library-in-objective-c/
https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816

Mac machines in devicelab are using Xcode 11.0 now, this is unblocked.

From #25676 (comment)

I was testing Swift plugins for add-to-app with both use_frameworks! (dynamic and static frameworks) and without (static libraries). I tested with flutter_photokit, CocoaPods 1.7.5 and Xcode 11 Seed 1.

As-is, only the existing Swift app succeeded when use_frameworks! was present. Without use_frameworks! I saw 'flutter_photokit/flutter_photokit-Swift.h' file not found. And the Objective-C host couldn't get past pod install:

[!] Unable to determine Swift version for the following pods:

- `flutter_photokit` does not specify a Swift version and none of the targets (`ScaryBugs`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.

use_frameworks! no use_frameworks!
Obj-C host [!] Unable to determine Swift version for the following pods: [!] Unable to determine Swift version for the following pods:
Swift host'flutter_photokit/flutter_photokit-Swift.h' file not found
Then I tried adding s.swift_versions = ['4.0', '4.2', '5.0'] to the flutter_photokit.podspec. Now the Objective-C host builds.

use_frameworks! no use_frameworks!
Obj-C host'flutter_photokit/flutter_photokit-Swift.h' file not found
Swift host'flutter_photokit/flutter_photokit-Swift.h' file not found
Then I tried this __has_include hack. CocoaPods/CocoaPods#7594 (comment)
I updated https://github.com/kmorkos/flutter_photokit/blob/master/ios/Classes/FlutterPhotokitPlugin.m to:

#import "FlutterPhotokitPlugin.h"
#if __has_include("flutter_photokit-Swift.h")
#import "flutter_photokit-Swift.h"
#else
#import <flutter_photokit/flutter_photokit-Swift.h>
#endif

@implementation FlutterPhotokitPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  [SwiftFlutterPhotokitPlugin registerWithRegistrar:registrar];
}
@end

And that fixed Swift. Objective-C now complains:

Undefined symbol: protocol conformance descriptor for Swift.String : Swift.CVarArg in Foundation
Undefined symbol: Darwin._convertDarwinBooleanToBool(Darwin.DarwinBoolean) -> Swift.Bool
Undefined symbol: _swift_getWitnessTable
Undefined symbol: protocol descriptor for Swift.CVarArg
Undefined symbol: _swift_getExistentialTypeMetadata
Undefined symbol: _swift_getForeignTypeMetadata
Undefined symbol: _swift_projectBox
etc

use_frameworks! no use_frameworks!
Obj-C hostUndefined symbol: protocol conformance descriptor for Swift.String : Swift.CVarArg in Foundation
Swift host ✅ ✅
I am running Xcode 11 and I found this note https://stackoverflow.com/a/57126566 and added "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)" to my app target's LIBRARY_SEARCH_PATHS and that gets me down to two undefined symbols:

Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements
Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility50

And now I'm in the bowels of Swift: https://github.com/apple/swift/blob/master/lib/IRGen/GenDecl.cpp#L454

So I added "$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)" to my app target's LIBRARY_SEARCH_PATHS.

use_frameworks! no use_frameworks!
Obj-C host ✅ ✅
Swift host ✅ ✅

@jmagman Please, doing all this you were able to solve the problem?

I'm trying to use "flutter udid plugin" but getting "The Swift pod flutter_udid depends upon SAMKeychain, which do not define modules." Please, see below link
GigaDroid/flutter_udid#2

I don't know what to do in order to get it to work.

Thank you in advance.

@marco2250 I don't think the module issue is strictly related. See:
#41007
The new podspec template: https://github.com/flutter/flutter/pull/41828/files#diff-c5debba4da2a234fe818947624b124d9R22 (you don't have the s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } part, though I wouldn't have expected that to be required for a Swift plugin?)
http://blog.cocoapods.org/CocoaPods-1.5.0/
ReactiveX/RxSwift#1800

Can you file a new flutter issue?

This issue is a mash of a few different problems, some of which were fixed, some are fixed in new plugins and need to be migrated with exiting Swift plugins, and some are still outstanding.

I'm going to get into the weeds here.

Plugin side

[!] Unable to determine Swift version for the following pods

TL;DR: Add s.swift_version = '5.0' to ios/your_project.podspec.
New Swift plugin podspec are generated with s.swift_version = '5.0' as of #44324. Existing Swift plugin authors should add this line to ios/your_project.podspec.
Example freshly generated ios/test_swift_plugin.podspec:

#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint test_swift_plugin.podspec' to validate before publishing.
#
Pod::Spec.new do |s|
  s.name             = 'test_swift_plugin'
  s.version          = '0.0.1'
  s.summary          = 'A new flutter plugin project.'
  s.description      = <<-DESC
A new flutter plugin project.
                       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.dependency 'Flutter'
  s.platform = :ios, '8.0'

  # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
  s.swift_version = '5.0'
end

If you have tested on versions of Swift other than 5.0, feel free to change this.
s.swift_versions = [ '4.0', '4.2', '5.0', '5.1' ]

fatal error: 'test_swift_plugin/test_swift_plugin-Swift.h' file not found

TL;DR: Update ios/Classes/YourPlugin.m to the following import snippet of Objective-C code.

New Swift plugins Objective-C implementation file have a new import pattern as of #44324 to support being used as libraries instead of frameworks so your users won't need use_frameworks!. Existing Swift plugin authors should update this import.
Example freshly generated ios/Classes/TestSwiftPlugin.m

#import "TestSwiftPlugin.h"
#if __has_include(<test_swift_plugin/test_swift_plugin-Swift.h>)
#import <test_swift_plugin/test_swift_plugin-Swift.h>
#else
// Support project import fallback if the generated compatibility header
// is not copied when this plugin is created as a library.
// https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816
#import "test_swift_plugin-Swift.h"
#endif

@implementation TestSwiftPlugin
...

Why is there a thin Objective-C wrapper class by default in Swift plugins?

❓❓❓
TL;DR: Don't worry about it
Apps had generated code to import plugin Objective-C headers instead of importing the clang module. See #41007 and https://github.com/flutter/flutter/pull/42204/files#r333285661
Once you feel confident all your app customers are on 1.10.15 or later and you have the Swift-foo, you can try to remove these wrapper Objective-C files. Please test your plugin on a fresh Objective-C flutter app before you publish to see how it's being used!

Objective-C app-side

Undefined symbol: _swift_ ...

TL;DR: Add use_frameworks! to your app's ios/Podfile
This is the result of Objective-C apps not being hooked up to look for Swift symbols at link time. You can fix this on the app side by using use_frameworks!, by adding a single dummy Swift file to tell Xcode to hook all that up, or (if you have the Xcode know-how) by adding $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) to LIBRARY_SEARCH_PATHS.

Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements

TL;DR: Add use_frameworks! to your app's ios/Podfile
Pretty much the same as the above, but on Swift 5. You can fix this on the app side by using use_frameworks!, by adding a single dummy Swift file to tell Xcode to hook all that up, or (if you have the Xcode know-how) by adding $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) to LIBRARY_SEARCH_PATHS.

This copy of libswiftCore.dylib requires an OS version prior to 12.2.0.

TL;DR: Add use_frameworks! to your app's ios/Podfile
On iOS >12.2 the Swift runtime is not embedded in the app, but is baked into the OS. You can fix this on the app side by using use_frameworks!, by adding a single dummy Swift file to tell Xcode to hook all that up, or (if you have the Xcode know-how) by adding /usr/lib/swift before $(inherited) in LD_RUNPATH_SEARCH_PATHS .

Why is there an Objective-C GeneratedPluginRegistrant wrapper class by default in Swift apps?

❓❓❓
TL;DR: Don't worry about it
Objective-C plugins were not defining clang modules, so could not be imported from Swift files. This was fixed for new Objective-C modules in #41828.

Summary

  • Swift apps should now be able to use (new or migrated) Swift and Objective-C plugins (on master channel at the moment)
  • Objective-C apps should be able to use (new or migrated) Swift plugins as frameworks (Podfile contains use_frameworks!)
  • Objective-C apps still cannot use Swift plugins as libraries (Podfile does not contain use_frameworks!), which is the default for a newly created Objective-C Flutter project. I'm going to use this issue to track these outstanding issues.

@jmagman Thanks for the detailed update!

Hey @jmagman, I couldn't fix the 'test_swift_plugin/test_swift_plugin-Swift.h' file not found here.

plugin/ios/TestSwiftPlugin

#import "TestSwiftPlugin.h"
#if __has_include(<test_swift_plugin/test_swift_plugin-Swift.h>)
#import <test_swift_plugin/test_swift_plugin-Swift.h>
#else
#import "test_swift_plugin-Swift.h"
#endif

@implementation TestSwiftPlugin
...

I'm getting 'test_swift_plugin-Swift.h' file not found.

Also, test_swift_plugin-umbrella.h in the example app is throwing: Include of non-modular header inside framework module 'test_swift_plugin' on #import "TestSwiftPlugin.h":

plugin/example/ios/.../test_swift_plugin-umbrella.h:

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif

#import "TestSwiftPlugin.h"
...

example/ios/Podfile:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  generated_key_values = {}
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) do |line|
    next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
    plugin = line.split(pattern=separator)
    if plugin.length == 2
      podname = plugin[0].strip()
      path = plugin[1].strip()
      podpath = File.expand_path("#{path}", file_abs_path)
      generated_key_values[podname] = podpath
    else
      puts "Invalid plugin specification: #{line}"
    end
  end
  generated_key_values
end

target 'Runner' do
  use_frameworks!
  use_modular_headers!
  
  # Flutter Pod

  copied_flutter_dir = File.join(__dir__, 'Flutter')
  copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
  copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
  unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
    # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
    # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
    # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

    generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
    unless File.exist?(generated_xcode_build_settings_path)
      raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
    end
    generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
    cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

    unless File.exist?(copied_framework_path)
      FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
    end
    unless File.exist?(copied_podspec_path)
      FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
    end
  end

  # Keep pod path relative so it can be checked into Podfile.lock.
  pod 'Flutter', :path => 'Flutter'

  # Plugin Pods

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.each do |name, path|
    symlink = File.join('.symlinks', 'plugins', name)
    File.symlink(path, symlink)
    pod name, :path => File.join(symlink, 'ios')
  end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

flutter doctor -v:

[✓] Flutter (Channel master, v1.12.6-pre.13, on Mac OS X 10.14.6 18G95, locale en-BR)
    • Flutter version 1.12.6-pre.13 at /Users/matheusromao/Library/flutter
    • Framework revision 0b502b1f8b (12 hours ago), 2019-11-20 22:11:51 -0500
    • Engine revision 7a77e3625d
    • Dart version 2.7.0

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/matheusromao/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/matheusromao/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.3, Build version 10G8
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 41.1.2
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.40.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.6.0

• No issues found!

Funny that #21096-comment fixed the problem locally, but when I tried in another app (other than the example one) the problem persisted.

Any ideas?

Just reverted everything back to before jmagman's comment, followed #41253-comment to downgrade cocoapods to 1.7.5 and now it works fine.

@arctouch-matheusromao I'm on CocoaPods 1.8.4 and master.
I deleted DerivedData, then:

$ flutter create -t plugin test_swift_plugin 
$ cd test_swift_plugin/example
$ flutter build ios
<success>
$ open ios/Runner.xcworkspace
<built in Xcode successfully>

Our Podfiles are identical. Am I missing a reproduction step? Did you change anything else in the example project?

Hmmm, something happened... Just tried on master, v1.12.9-pre.13 and it's working 🤷‍♂

  • Updated cocoapods to 1.8.4
  • Deleted Podfile.lock and Pods/
  • Run pod update
  • Run example from xcode

All good then. Thanks again!

On my hand, I must share my experience with the plugin open_appstore, which has the same issue apparently.

When trying to flutter build ios, first issue:

[!] Automatically assigning platform ios with version 8.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

#11000 (comment) fixed my first issue, pretty easily.

Then, second issue: I've faced this terrible error message, very complicated to get it fixed, after hours of effort :

The "Swift Language Version" (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.

I've added the following changes to ios\Podfile :

[...]
target 'Runner' do
  use_frameworks!       # <------ Add this line
[...]
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '5.0'     # <------- Add this line
    end
  end
end

Apparently, not enough - I was still facing the issue after flutter build ios (even though I deleted Podfile.lock and ios\Pods and re-run pod install)

I know the correct fix would be the one suggested by @jmagman #16049 (comment)

I guess I'm using an Objective-C project. I know I need to add s.swift_versions = ['4.0', '4.2', '5.0'] to the file flutter_open_appstore.podspec, but I cannot manage to find this file on my Mac (I assume the files are directly downloaded from git open_appstore project, so only the developer of this plugin can make the change...)

I ended up using the workaround as suggested by @mravn-google : #16049 (comment)

  1. Open Runner.xcworkspace file under ios folder
  2. On the menu: File > New -> File -> Swift File
  3. Type any name for the file (doesn't matter), make sure the file will be created in ios folder and continue
  4. When Xcode prompts dialog if you wish to create Bridging Headers, click on Yes (this is important)
  5. Still in Xcode, review the setting Swift Language Version in Runner > Targets > Runner > Build Setings and make sure the selected version is Swift 5
  6. Open a command prompt, browse to your Flutter project and type flutter clean
  7. Then, cd ios
  8. rm -Rf Pods/
  9. rm Podfile.lock (if needed)
  10. Finally: pod install --repo-update

After this, I was able to build iOS archive (flutter build ios).

Perhaps it's also important to mention that I'm using version 1.8.4 of cocoapods, Xcode version 10.2.1 and flutter version 1.9.1+hotfix4

I hope my experience can save a headache to any other iOS novice developers like me :)

Thank you all for your solutions!

In case you follow all the steps in #16049 (comment) and running pod install --repo-update you get another error such as:

- `open_appstore` does not specify a Swift version and none of the targets (`Runner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.

Using XCode 11.3.1 I wasn't able to find Swift Language Version you may need to add an extra step to make it work:

  1. In Xcode, under Runner > Targets > Runner > Build Settings > Add User-Defined Setting and add SWIFT_VERSION with 5.0
  2. rm -Rf Pods/
  3. rm Podfile.lock (if needed)
  4. Again: pod install --repo-update

I Hope it helps.

Thanks a lot @nerder for this addition, it definitely helps!

I was also struggling with my own instructions a few days ago, I wasn't able to find Swift Language Version with the new Xcode update, but you gave the correct fix!

Thanks again!

Hi,
I am using Flutter V1.12.13+hotfix-9 in Stable channel.
Cocoapods V1.8.4
XCode 11.3

I am getting below error while building and archiving iOS app.

" /Users//.pub-cache/hosted/pub.dartlang.org/device_calendar-3.1.0/ios/Classes/DeviceCalendarPlugin.m:2:9: fatal error:
'device_calendar/device_calendar-Swift.h' file not found
#import <device_calendar/device_calendar-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users//.pub-cache/hosted/pub.dartlang.org/device_calendar-3.1.0/ios/Classes/DeviceCalendarPlugin.m:2:9: note: did not find header 'device_calendar-Swift.h'
in framework 'device_calendar' (loaded from '/Users//build/ios/Release-iphoneos/device_calendar')"

and Sometimes
"Umbrella header 'device_calendar-umbrella.h' not found"

Any idea?

@ssivagnanam If your app is Objective-C, you can add use_frameworks! to your ios/Podfile.

#16049 (comment)

More background for why #import <flutter_photokit/flutter_photokit-Swift.h> doesn't work for Swift libraries (no use_frameworks!):

https://paul-samuels.com/blog/2018/01/14/swift-static-library-in-objective-c/
https://forums.swift.org/t/swift-static-libraries-dont-copy-generated-objective-c-header/19816

If your app is Swift, you can add SWIFT_VERSION to your ios/Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
...
      config.build_settings['SWIFT_VERSION'] = '5.0' // Or whatever Swift version your app is using that works with your plugins
    end
  end
end

The real answer is that the maintainers of device-calendar update their podspec to support Swift, see #44324 and #16049 (comment)

  s.swift_version = '5.0'