LoginSignup
20
15

More than 3 years have passed since last update.

Flutter Pluginの利用でSwiftエラーが出る場合の対処方法

Last updated at Posted at 2019-07-14

背景

自分は、image_downloaderという「指定したURLの画像を端末に保存する」Pluginを作っていて、嬉しいことにまあまあ利用されているようです。
しかし、Flutterの問題でPlugin自体のバグではないのにissueでバグとしてたびたび報告されるので、それの対処方法と何故、それが起きるのか記述しておきます。(たとえ、トラブルシューティングに書いても読まない人が多いのかも)

これは、Swiftで作成されているFlutterのPluginを利用し、且つ、プラットフォームチャンネル言語でSwiftを選択しなかった場合に起きます。

エラー内容

以下のようなエラーが表示されます。

=== BUILD TARGET image_downloader OF PROJECT Pods WITH CONFIGURATION Debug ===
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 3.0, 4.0, 4.2. This setting can be set in the build settings editor.
=== BUILD TARGET image_downloader OF PROJECT Pods WITH CONFIGURATION Debug ===
~/.pub-cache/hosted/pub.dartlang.org/image_downloader-0.11.2/ios/Classes/ImageDownloaderPlugin.m:2:9: fatal error: 'image_downloader/image_downloader-Swift.h' file not found
#import <image_downloader/image_downloader-Swift.h>
[!] Unable to determine Swift version for the following pods:

- `image_downloader` 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.

理由

この問題はフラッター側にあるため、swiftで作成されたすべてのプラグインに同じ問題があります。

# 対処方法

これを解決するためにいくつかの設定をする必要があります。

  1. ブリッジングヘッダーを作成する必要があります。 XCodeでプロジェクトを開きます。
  2. File -> New -> File -> Swift Fileを選択し、Runnerディレクトリに作成します。それからBridging Headerも作成し、ダイアログ上でクリックします。

(これはXCode - > Build SettingsでSWIFT_VERSION、SWIFT_OBJC_BRIDGING_HEADERなどを設定しているのと同じことです。)

3.ios/PodfileのRunnerブロックにuse_frameworks!があることを確認してください。

target 'Runner' do
  use_frameworks!

4.基本的にはこれで問題ありませんが、うまくいかない場合は次のようにします。

$ flutter clean
$ cd ios
$ rm -rf Podfile.lock
$ rm -rf Pods
$ pod install --repo-update 

これで動作するはずです。

20
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
15