LoginSignup
2
2

More than 3 years have passed since last update.

AWSMobileClientのpod installがSWIFT_VERSIONのエラーで止まるときの対応

Posted at

AWSMobileClientがインストールできない

新しくiOSアプリを作る場合にはまずあり得ないと思いますが、古いアプリの改修などの場合はコードが全てObjective-Cで書かれているケースも珍しくないと思います。今回、そういうケースでAWSMobileClientがインストールできないという現象に遭遇したので記録しておきます。

つまり、どういうことかというと

  • Objective-Cだけで書かれたiOSアプリにAWSMobileClientをpod installしようとすると失敗します。
  • Bridging Headerを生成してあげましょう。
  • ダミーのSwiftファイルを作成するだけで、Xcodeが自動生成してくれます。

以下、詳細です。

発生した現象

Cocoapodsを使ってAWSMobileClientをインストールしようとするとUnable to determine Swift versionエラーになる。

Podfile

$ cat Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'test' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for test
  pod 'AWSMobileClient'

  target 'testTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'testUITests' do
    # Pods for testing
  end

end

pod install実行結果

$ pod install
Analyzing dependencies
Downloading dependencies
Installing AWSAuthCore (2.13.2)
Installing AWSCognitoIdentityProvider (2.13.2)
Installing AWSCognitoIdentityProviderASF (1.0.1)
Installing AWSCore (2.13.2)
Installing AWSMobileClient (2.13.2)
[!] Unable to determine Swift version for the following pods:

- `AWSMobileClient` does not specify a Swift version and none of the targets (`test` and `testUITests`) 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.

実行環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G4032

$ xcodebuild -version
Xcode 11.3.1
Build version 11C504

諸般の事情でまだMojaveです。従ってXcodeも現行版(11.4)ではなく11.3系列の最新版になっています。

再現手順

Xcode、Cocoapodsなどのインストールおよび設定は正常に完了しているものとします。

  1. Xcodeから新規iOSアプリを作成し、開発言語としてObjective-Cを選択する
  2. pod init
  3. Podfileを編集し、pod 'AWSMobileClient'の記述を追加
  4. pod install → Unable to determine Swift versionエラー発生

原因

エラー本文に「Please contact the author」とあるように、根本的な原因はAWSMobileClient側にあるものと思われます。が、とりあえずXcodeプロジェクト内にBridging Headerが存在していればエラーは発生しないようです。

対策

Bridging Headerは単なるヘッダファイル(*.h)なので、手動で作成することも可能です。しかし、Objective-Cだけで書かれたアプリにSwiftファイルを追加するとXcodeが自動生成してくれますので、ここではその機能を利用してみます。

  1. メニューから File -> New -> File...を選択
  2. Swift Fileの作成を選択
  3. 適当な場所を選んで Create を選択(ダミーのSwiftファイルが生成されます)
  4. Bridging Headerの設定をするか尋ねられるので「Create Bridging Header」を選択

これで空のBridging Headerが生成されるので、ダミーとして作成したSwiftファイルは削除してかまいません。

結果

再度 pod install を実行してみます。

$ pod install
Analyzing dependencies
Downloading dependencies
Installing AWSAuthCore (2.13.2)
Installing AWSCognitoIdentityProvider (2.13.2)
Installing AWSCognitoIdentityProviderASF (1.0.1)
Installing AWSCore (2.13.2)
Installing AWSMobileClient (2.13.2)
Generating Pods project
Integrating client project

Pod installation complete! There is 1 dependency from the Podfile and 5 total pods installed.

無事インストールに成功しました。

参照

それにしても

今時、Objective-Cオンリーの環境に最新のSDKを入れようとするのが間違っているのか…?

2
2
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
2
2