euphonictechnologies’s diary

Haskell超初心者の日記です。OCamlが好きです。

follow us in feedly

Could not build Objective-C module 'GoogleMobileAds' とXcodeに怒られたら

久しぶりにiOSアプリをビルドしようとして失敗しました。

やっぱりか、と思いつつエラーが一つだけなことに気づきました。GoogleMobileAdsのモジュールが無いという怒られ方です。これなら楽ちんに直せそうです。

とりあえず、gitをきれいにしていつでも戻せるようにしてからはじめましょう。コミットしてないファイルがあればどこかにとっておくか、コミットしちまいましょう。

まずは原因の切り分け

まっとうなエンジニアリング的アプローチをとってみるとここは原因の切り分け。つまり、GoogleMobileAds以外は大丈夫なことを確認するために、Adを外してビルドしてみます。

おそらく編集するのは

  • ViewControllerからimport GoogleMobileAdsを削除する

  • さらに、同じファイルからGADBannerViewとかGoogleMobileAdsを使用しているViewをViewに変換する

  • そのViewの初期化処理をコメントアウトする

私のプロジェクトの場合は以下の感じです。

Preparation for upgrade, running ok on iPhone X real · ysnrkdm/FlatReversi@07cedc7 · GitHub

さらに

  • プロジェクト設定からGoogleMobileAdsフレームワークがあれば、それも削除する

f:id:euphonictechnologies:20181001223349p:plain

これでとりあえずビルドが走るはず。

GoogleMobileAdsをPodから入れ直す

というわけで、ぶっ壊れてるのはCocoaPodsで昔いれたライブラリのようです。

こういうとき一番に試すのは、入れ直しです。よっしゃ。Lockファイルに全部残っているのでpod installしても同じバージョンが入るか、そのバージョンの存在を確認してするっと抜けられてしまいます。

Analyzing dependencies
Downloading dependencies
Using Firebase (3.6.0)
Using FirebaseAnalytics (3.4.2)
Using FirebaseInstanceID (1.0.8)
Using Google-Mobile-Ads-SDK (7.11.0)
Using GoogleInterchangeUtilities (1.2.1)
Using GoogleSymbolUtilities (1.1.1)
Using GoogleUtilities (1.3.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 7 total pods installed.

バージョン古いですね。入れ直ししましょう。まずはインストールされているライブラリを全部消します。Podfileの中身は、現在こんな感じ。

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '7.0'

target 'FlatReversi' do
  pod 'Firebase/Core'
  pod 'Firebase/AdMob'
end

こんな感じになっているファイルを、まず、消すために、全部消して別の関係ないライブラリをいれます。

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '7.0'

target 'FlatReversi' do
  pod 'Async'
end
$ pod install
source 'https://github.com/CocoaPods/Specs.git'
Analyzing dependencies
Removing Firebase
Removing FirebaseAnalytics
Removing FirebaseInstanceID
Removing Google-Mobile-Ads-SDK
Removing GoogleInterchangeUtilities
Removing GoogleSymbolUtilities
Removing GoogleUtilities
Downloading dependencies
Installing Async (0.2.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

消えました。やりますねぇ。それで、ファイルを元に戻して入れ直します。Podfileはこんな感じ。

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '7.0'

target 'FlatReversi' do
  pod 'Firebase/Core'
  pod 'Firebase/AdMob'
end

で、pod installを実行してみると。

$ pod install
Analyzing dependencies
Removing Async
Downloading dependencies
Installing Firebase (4.13.0)
Installing FirebaseAnalytics (4.2.0)
Installing FirebaseCore (4.0.20)
Installing FirebaseInstanceID (2.0.10)
Installing Google-Mobile-Ads-SDK (7.30.0)
Installing GoogleToolboxForMac (2.1.4)
Installing nanopb (0.3.8)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 7 total pods installed.

バージョンが全然違いますね。やりました。これでビルドしてみると、

f:id:euphonictechnologies:20181001224702p:plain

Test Adが表示されるようになりました。

まとめ

ホビープログラミングやっててCocoaPodsで問題が起きたら、ざっくり全部消してもう一回入れ直すといいことがあるかもです。

もちろん、業務用の場合は、まあ、ね。