LoginSignup
10
9

More than 3 years have passed since last update.

【Flutter】プラグインを使用した時に出るSwiftバージョン指定エラーの解決

Last updated at Posted at 2019-11-24

問題

下記エラーの対処法です。

Flutterで特定のプラグインを使用した状態で、iOSでデバッグしようとすると発生します。

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

app_reviewの部分は使用するプラグインによって変わります。

SWIFT_VERSIONを指定しろ!!と言っています。

もしかしたら、エラーメッセージの中に下の奴が黄色で強調されていて、エラーの本体のように見えてしまうかもしれませんが、違います。

上の「SWIFT_VERSION」の方が本体です。

これはエラーの本体ではない
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.

エラーメッセージのバリエーション

このようなエラーメッセージが出るケースもありました。

Error output from CocoaPods:
↳
    /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/mysql/bin in PATH, mode 040777

    [!] 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`.

Error running pod install

注意

この記事の解決策を試す際には必ず

flutter clean

を実行してからビルドするようにしてください。

でないと、全然関係ないエラーを引き起こして混乱します。

解決策

この解決策は古いです。下の「解決策2」を先にお試しください。

ステップ1

まずはこちらの記事を、作者の方に感謝しながら参照して、XCode経由で、デフォルトのSwiftファイルとデフォルトのBridgingHeaderファイルを作成します。

これで解決すれば完了です。

ステップ2

それでも解決しない場合の解決策はこちらのissueのこのコメントです。

リンク先のソースコードをそのまま引用します(引用日:2019-11-24)

ios/Podfile
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

ios/Podfileの適切な場所に、

use_frameworks!

config.build_settings['SWIFT_VERSION'] = '3.2'

の二行を追加してください。

これで解決すれば完了です。

ステップ3

ただ、おそらく、下記のようなエラーメッセージが出ると思います。

** BUILD FAILED **
Xcode's output:
↳
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 4.0, 4.2, 5.0. This setting can be set in the build settings editor.

この場合は、Swiftのバージョンをエラーメッセージで指定されている番号に書き換えてください。

config.build_settings['SWIFT_VERSION'] = '3.2'

config.build_settings['SWIFT_VERSION'] = '5.0'

これで解決するはずです。少なくとも私は解決したんですよ😃

解決策2 (追記2020-01-10)

Flutter自体のバージョンが上がり、上記の解決策を実行した後でも次のようなエラーが出るようになりました。

Warning: Podfile is out of date
  This can cause a mismatched version of Flutter to be embedded in your app, which may result in App Store submission rejection or crashes.
  If you have local Podfile edits you would like to keep, see https://github.com/flutter/flutter/issues/24641 for instructions.
To regenerate the Podfile, run:
  rm ios/Podfile

そこで、言われたとおりに

rm ios/Podfile

を実行してios/Podfileを消します。

そもそもこのios/PodfileはFlutterによって作られたものですから、消しても再生成されるので問題ないです。

消したら、もう一度デバッグを試みます。

すると、自動で新しいios/Podfileが生成されて、正常に動きます。

例のuse_frameworks!の行もきちんと追加されています。

現在(2020-01-10)では、この解決策が最善と思われます。

もしこれで解決しない場合は、1つ目の解決策のステップ1でBridgingHeaderを作成することをお試しください。

10
9
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
10
9