LoginSignup
10
9

More than 5 years have passed since last update.

Cocos2d v3 CocoaPodsのインストールと設定

Last updated at Posted at 2015-05-17

前回まで

Cocos2dの導入を行い、出来上がったものを確認しました。

今回行う事

今回はSpriteBuilderとXCodeを連携するのですが、その前にCocoaPodsを導入します。
CocoaPodsを先に導入しておけば、今後使用するライブラリーの導入が楽になります。
※今回はiOS7.0以降を対象にするためCocoa Touch Frameworkは使用しません。

CocoaPodsの導入

CocoaPodsはすでにインストール済みであることを前提に話を進めます。
前回まで作成したShootBalloon.spritebuilderをXCodeで開いている方は閉じてください。

Podファイルの作成

その後、ShootBalloon.spritebuilderの直下にPodfileを作成して以下のように記載してください。

Podfile
platform :ios, '7.0'

pod 'GoogleAnalytics-iOS-SDK'
pod 'Google-Mobile-Ads-SDK', '~> 7.0'
pod 'NendSDK_iOS'

ここでは今後使用する予定である、

  • アクセス状況確認用のGoogleAnalytics
  • Google広告用のAdMob
  • 日本最大手広告のAppBank(Nend)

上記のライブラリーを事前に入れておきます。

Podのインストール

$> cd ShootBalloon.spritebuilder/

でルートディレクトリに移動して

$> pod install

を行って各ライブラリーを入れてください。

インストールが終わると以下のエラーが表示されるので、指示通り解決していきます。

[!] The `ShootBalloon iOS [Debug]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `ShootBalloon iOS [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `ShootBalloon iOS [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `ShootBalloon iOS [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

ワークスペースを開きます。

今まではShootBalloon.xcodeprojファイルを開いてましたが、Podsインストール後からはShootBalloon.xcworkspaceファイルができているので、それをXCodeで開きます。

設定を変更します。

Build Settingsを開いててHEADER_SEARCH_PATHSを検索します。

setting.png

こちらに$(inherited)を追加します。

setting2.png

同じ要領でOTHER_LDFLAGSにも追加します。

念のため再度確認します。

$> pod install

こちらのコマンドをもう一度実行して上記のワーニングが出てなければ完了です。

Swiftでこれらのファイルを使えるようにする。

前回説明をしたBridging-Header.hの一番下に以下の記述を行います。

Bridging-Header.h
...前略

// AdMob
@import GoogleMobileAds;

// google analytics
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"

// Nend
#import "NADView.h"

これで準備完了です。
まだこれらのライブラリは使用しませんが、事前に設定しておきます。

なぜ先にCocoaPodsを設定するのか

今回のような小さいプロジェクトではいつ追加しても問題ないのですが、ある程度の規模のプロジェクトで後になってCocoaPodsを導入すると問題が発生する場合があります。
個々で導入したライブラリと競合して動かなかったり、メンバー毎にライブラリの入れ方が違ってしまうことがあるため初めにライブラリ管理方法を共有することが重要だと僕は考えてます。

特にスマホ開発はStrutsやRailsなどのようなフレームワークが無いため、メンバー固有のプログラムが入りやすく汚くなりがちです。
なので、僕はできるだけ初めに環境を整えてその環境を共有させてプロジェクトを進めて行くことを提唱してます。

次回は

SpriteBuilderとXCodeで画面遷移するについて書いてます。

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