問題
- Objective-Cのプロジェクト
- その中でSwiftファイルを作成
- そのSwiftファイルからmoduleをimportしようとしたら、ビルドエラー
Could not build Objective-C module ‘Clarifai_Apple_SDK’
(Clarifaiは画像認識系のAIサービス)
上記のエラーに加え、下記のエラーが大量に
Include of non-modular header inside framework module ‘******’
原因
Podfileの# use_frameworks!
がコメントアウトされてた。
CocoaPodをSwiftから使うときは、use_frameworks!
が記述されている必要がある。
https://qiita.com/taketin/items/8264aeebc5a626c6d48f
Swiftプロジェクトは、上記箇所がデフォルトで記述されているが、
Objective-Cプロジェクトは、Podfileの上記箇所がデフォルトでコメントアウトになっている。
つまり、Podfileは、$ pod init
で生成された時点で、
プロジェクトの言語(Objective-C/Swift)に応じて下記のように微妙に中身が違う。
Objective-CのPodfile # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
SwiftのPodfile # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
しらなかったよぉぉぉぉぉぉー(ฅωฅ)
英語のコメントなんて読まないし!(読めない)
3時間くらいまるまる悩み、
いくつも新規にプロジェクト作り直して、
SwiftプロジェクトならビルドできるのにObjective-Cはできないことがわかったから
両者のファイル差分をいちいち観察して、ようやく気づけました。笑
最初からSwiftで作られたプロジェクトはuse_frameworks
のコメントが外れているから、ビルドエラーも起こらなかった、というわけのようです。
解決策
- Podfileの
# use_frameworks!
をuse_frameworks!
にする - ターミナルで
$ pod update
- XCodeで「option ⌥」+「command ⌘」+「shift ⇧」+「K」(Clean Build Folder)
- 再ビルド!!!
コメント