まだまだお付き合いしないと行けないCocoaPods
Carthageが台頭して来て、利用するSDKがCarthage対応していたら大抵Carthage版をinstallするのですが、まだまだCocoaPodsで管理されているSDKが多い為、iOSエンジニアだとCocoaPodsを使うことを避けては通れません。
特にGoogle製SDKを利用しようと思ったらCocoaPodsは確実に登場します。
(決して駄目と言っているんじゃないですよ、Carthageと比較するとどうしても見劣りするだけで…)
そんなCocoaPodsですが、ちょくちょく躓いたり、困ったりする時があり、その都度このブログに備忘録的に残しては来たのですが、
- 記事の数が多くなってきた
- それなりにアクセスがある = 他にも困っている人が結構いる
という理由で、CocoaPodsを利用して困った・躓いたをまとめようと思います。
XCodeで Class ○○ is implemented in both ○○ and One of the two will be used. Which one is undefined.のエラーが出る
事象
以下のエラーが多発した時
Class {$クラス名} is implemented in both {$FrameworkPath} and {$AppPath}. One of the two will be used. Which one is undefined.
解決策
CocoaPodsでSDKを入れた直後にこのエラーが出た場合は、おそらくPodfileのTarget指定がミスっています。
必要なTargetにSDKを記載します。
例えば、アプリ本体にSDKを入れないと行けないのに、以下のようにEmbedded FrameworkにSDKを入れてしまった時とかは、
target '{$Embedded Frameworkの名前}' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for {$Embedded Frameworkの名前}
# add the Firebase pod for Google Analytics
pod 'Firebase/Analytics'
pod 'Firebase/Core'
pod 'Firebase/Firestore'
pod 'Firebase/Auth'
# Optionally, include the Swift extensions if you're using Swift.
pod 'FirebaseFirestoreSwift'
# add pods for any other desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods
target '{$Embedded Frameworkの名前}Tests' do
# Pods for testing
end
end
target '{$AppName}' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
target '{$AppName}Tests' do
inherit! :search_paths
# Pods for testing
end
target '{$AppName}UITests' do
# Pods for testing
end
end
以下のようにアプリ本体のTargetにSDKを入れるようにします。
target '{$Embedded Frameworkの名前}' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for {$Embedded Frameworkの名前}
target '{$Embedded Frameworkの名前}Tests' do
# Pods for testing
end
end
target '{$AppName}' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# add the Firebase pod for Google Analytics
pod 'Firebase/Analytics'
pod 'Firebase/Core'
pod 'Firebase/Firestore'
pod 'Firebase/Auth'
# Optionally, include the Swift extensions if you're using Swift.
pod 'FirebaseFirestoreSwift'
# add pods for any other desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods
target '{$AppName}Tests' do
inherit! :search_paths
# Pods for testing
end
target '{$AppName}UITests' do
# Pods for testing
end
end
ld: framework not found {ライブラリ名}のエラーが出る
事象
コンパイル時に、以下のようにライブラリが見当たらない系のエラーが出る
ld: framework not found {ライブラリ名}
解決策
原因によって色々解決策が別れますが、pod installしなおして見た時に、以下の警告が出ていないか確認してみてください。
[!] The {$AppName} target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-{$AppName}-{$AppName}UITests/Pods-{$AppName}-{$AppName}UITests.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
この場合は、ちゃんと警告を潰しましょう。
以下は、$(inherited)をbuild settingsに設定したときの例です

この警告が出て、ld: framework not found {ライブラリ名}だった場合はこれで直ります。
No such module XXXX 系のエラー
事象
コンパイルやArchive時に以下のようにモジュールが見つからない系のエラーが出る
No such module 'モジュール名'
CocoaPodsを使っているとにくいほどよく見るエラー
解決策
いろんな事象が折り混ざってますが、以下を試してみてください
XCode, Mac再起動
これで結構治ったりします
Clean実行
クリーンしてリビルドで結構治ったりします
Pods入れ直し
以下で一度消して
pod deintegrate
入れ直す
pod install
iOSのTargetバージョンがあってるか
上記でも直らない場合( 私がそうでした )、私の場合、PodFileで指定したバージョンとXCodeで設定しているiOSとのバージョンで差異があってエラーを起こしていました。 (Archiveの時しか発生していなかったので本当に難航しました)