LoginSignup
6
8

More than 5 years have passed since last update.

CocoaPodsへのライブラリのアップロードと注意点

Last updated at Posted at 2016-10-12

はじめに

CocoaPodsへライブラリを公開するにあたり、気をつける点と簡単な手順まとめておきます。

実行環境

  • OS X El Capitan 10.11.5
  • git version 2.8.4 (Apple Git-73)
  • CocoaPods 0.39.0 ※後述
  • Xcode Version 8.0

CocoaPodsへのライブラリのアップロードの手順

1. ライブラリの雛形作成

$ pod lib create [Library name]

2. ライブラリ、Exampleの実装

3. podspecファイルの修正

4. Githubに公開

4.1. Githubpush

$ git add .
$ git commit -m "commit message"
$ git remote add origin https://github.com/[User name]/[Library name].git
$ git push origin master

4.2. タグをつけてGithubpush

$ git tag 0.1.0
$ git push --tags

5. podspecのバリデーションを行う

$ pod spec lint LibraryName.podspec

6. CococaPodにアカウント登録

$ pod trunk register [your mail address] [your name]

ここでCococaPodからメールが来るので確認する。

$ pod trunk me

で情報が表示されればOK

7. CocoaPodsに公開

$ pod trunk push LibraryName.podspec 

ここまで、簡単にCocoaPodsでライブラリの作成から公開までの簡単な手順です。
何も問題なければ簡単にできると思います。

注意点、はまったこと

今回いくつかのエラーではまっていたので、エラー内容と解決策をまとめておきます。

1. xcodebuildのエラー

$ pod spec lintでのバリデーションエラー

エラー内容

- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
    - NOTE  | [iOS] xcodebuild:  xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

解決策

CommandLineToolsにXcodeのバージョン指定がなければ、エラーが出るようです。

Xcode/Preferences/Locations/CommandLineToolsでXcodeのバージョンを指定する

スクリーンショット 2016-10-12 11.13.26.png

参考: xcode-select active developer directory error

2. Use Legacy Swift Language Version

$ pod spec lintでのバリデーションエラー

=== CLEAN TARGET LibraryName OF PROJECT Pods WITH THE DEFAULT CONFIGURATION (Release) ===

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)
=== BUILD TARGET LibraryName OF PROJECT Pods WITH THE DEFAULT CONFIGURATION (Release) ===

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.

** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
 -> LibraryName (0.1.0)
    - ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.

解決策

podのバージョンを 1.1.0.rc.2に指定して、.swift-versionファイルにバージョン番号を指定してあげれば解決できます。

$ echo 2.3 > .swift-version

or

$ echo 3.0 > .swift-version

.swift-versionを作成したらgitpush

CocoaPodsのバージョンが0.39.0なので1.1.0.rc.2に変更

$ gem uninstall cocoapods
$ gem install cocoapods -v 1.1.0.rc.2

参考: Swift 3 & CocoaPods

3. pod trunk pushでのエラー

$ pod trunk push LibraryName.podspec

エラー内容


### Error

NoMethodError - undefined method `swift_version=' for #<Pod::Validator:0x007f89ab9224f8>

解決策

CocoaPodsのバージョンを最新1.1.0.rc.3に変更

$ gem uninstall cocoapods
$ gem install cocoapods -v 1.1.0.rc.3

終わりに

今回、CocoaPodsSwiftのバージョンの問題でエラーが出てたと思います。メジャーバージョンアップの際には特にバージョンに意識することが必要ですね。

6
8
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
6
8