毎回忘れるのでメモ。
前提
- すでに自作ライブラリを CocoaPods に公開済み
最初にライブラリを公開する際は下記記事がとても参考になる。
手順
1. ライブラリを更新
変更内容を push しておく。
実際に pod install して使えるかテストしておくこと。ブランチ指定が便利。
pod 'FoursquareAPIClient', :git => 'https://github.com/koogawa/FoursquareAPIClient.git', :branch => 'develop'
1. podspec ファイルを編集
s.version を上げるのを忘れずに。
2. git にタグ追加
$ git tag -a 2.0.0 -m 'Compatible Swift 3.0' $ git push origin 2.0.0
3. podspec をバリデーション
$ pod spec lint
なんか怒られたら直す。
Swift 3対応でちょっとハマったので下の方に対処法を書いておいた。
4. CocoaPodsへ公開
pod trunk push FoursquareAPIClient.podspec
トラブルシューティング
困ったらとりあえず pod を最新に上げてみる
$ sudo gem install cocoapods
Swift 3 対応
pod spec lint したら次のエラーが出た。
Check dependencies
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.
** CLEAN FAILED **
The following build commands failed:
Check dependencies
(1 failure)
ググったら、同じように困っている人がいた。
Swift 3 CocoaPod does not pass lint - Stack Overflow
cocoapod を最新に上げて、.swift-version ファイルを追加しないといけないらしい。
↑これは解決したけど、また新たなエラーが。
で解決。
Swift 5 対応
pod spec lint したら次のエラーが出た。
** BUILD FAILED **
Testing with `xcodebuild`.
-> FoursquareAPIClient (5.0.0)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | xcodebuild: error: SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0. (in target 'App')
- NOTE | xcodebuild: error: SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0. (in target 'FoursquareAPIClient')
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error.
SWIFT_VERSION に 3.0 なんか指定してないよ!と思ったけど、podspec ファイルに
s.swift_version = '5.0'
を指定してないのが原因?
さらに、Swift 3 対応のときに追加した.swift-version ファイルも今は deprecated らしいので削除。
これでも解決しない場合は workaround だけど --allow-warnings オプションで回避できるらしい。