Cocoapodsを使って依存ライブラリをインストールした時に色々ハマったので解消方法をメモ。
環境
- Cocoapods version 1.0.1
The dependency xxxx
is not used in any concrete target.
以下のようなPodfileを作成し、pod install
コマンドを実行したらエラーが。
pod 'AWSAPIGateway', '~> 2.2.1'
$pod install
[!] The dependency `AWSAPIGateway (~> 2.2.1)` is not used in any concrete target.
メッセージを読むと targetが指定されていないと書いているようにみえるが。。
調べてみると以下の記事が。
Cocoapods 1.0.0から podfile でターゲットを指定しないといけないようです。
pod init
コマンドで対象のプロジェクトのPodfileのテンプレを作成し、それに追記するのが良さそう。
$pod init
$cat Podfile
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'HelloWorld' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for HelloWorld
target 'HelloWorldTests' do
inherit! :search_paths
# Pods for testing
end
target 'HelloWorldUITests' do
inherit! :search_paths
# Pods for testing
end
end
あとは上記を変更すればOKです。
pod repo updateが失敗する
解消したと思ったら次のようなエラーが。
$pod install
Analyzing dependencies
[!] Unable to satisfy the following requirements:
- `AWSAPIGateway (~> 2.4.7)` required by `Podfile`
None of your spec sources contain a spec satisfying the dependency: `AWSAPIGateway (~> 2.4.7)`.
You have either:
* out-of-date source repos which you can update with `pod repo update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
pod install した時に pod repo update
コマンドを実行しないよというメッセージが。
じゃあと実行してみました。
$pod repo update
Please commit your changes or stash them before you can merge.
error: The following untracked working tree files would be removed by merge:
Specs/ALSPopView/1.0.1/ALSPopView.podspec.json
Specs/ALSPopView/1.0.2/ALSPopView.podspec.json
Specs/ALSPopView/1.0/ALSPopView.podspec.json
Specs/AdMobMediationAdapterFB/1.2.1.1/AdMobMediationAdapterFB.podspec.js
--versbose オプションを付けて実行する分かるのですが、内部的にはgit pull
を実行しているようで恐らくgit pull しているレポジトリの所でcommitされていないファイルなどがあるようでエラーになっているような。
調べてみると以下のGithub の issueが。
git reset HEAD --hard
で一旦HEADに戻せば大丈夫とのことでやってみます。
$cd ~/.cocoapods/repos/master/
$git reset HEAD --hard
再度実行してみます。
$pod repo update
・・・
CocoaPods 1.1.0.rc.2 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.1.0.rc.2
成功。
CococPodsの1.1.0rc2があるよと言われるがtest versionらしいのでやめときます。。。
問題解消後、pod install
で依存ライブラリがインストールできました。
良かったー。