酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

とあるiOSアプリでApp Groupsの処理を追加したらビルドエラーが発生した話

Today Extension対応やAppleWatch対応のためか、iOS 8以降ではApp Groupsと呼ばれる仕組みが追加されました。今回、弊社で開発中の「hoge.app (仮名)」でも採用することになりました。

Xcodeでのビルドを自動化するxcodebuildコマンドとIPAファイルを作成してiTunes Connect(Testflight)に投げる方法 - 酢ろぐ!」にも書いたように、Jenkinsを使ってipaファイルをTestFlightに投げるまでの処理を自動化しているのですが、ビルドはできるけれどiTunes Connect(TestFlight)ではじかれてるという現象が発生しました。

今まで証明書とプロビジョニングプロファイルとの不一致でipaファイルを生成できないことは多々あったのですが、ipaファイルが生成できるけれどアップロードに失敗するというケースは経験がなかったので問題に気付くのに時間がかかってしまいました。

以下のようなログが出ていました。

2015-02-19 22:07:23.399 altool[5610:13359] *** Error: ( "Error Domain=ITunesConnectionOperationErrorDomain Code=1091 \"Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'com.apple.security.application-groups' in 'Payload/hoge.app/hoge'.\" UserInfo=0x7fe8e2f4aa50 {NSLocalizedRecoverySuggestion=Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'com.apple.security.application-groups' in 'Payload/hoge.app/hoge'., NSLocalizedDescription=Invalid Code Signing Entitlements. The entitlements in your app bundle signature do not match the ones that are contained in the provisioning profile. The bundle contains a key that is not included in the provisioning profile: 'com.apple.security.application-groups' in 'Payload/hoge.app/hoge'., NSLocalizedFailureReason=iTunes Store operation failed.}" )

結論としては、hogeプロビジョニングプロファイルに「App Groups」のサービスを追加すると、今まで使っていたプロビジョニングプロファイルがiTunes Connect側で無効扱いされるようになります。

無効扱いとは言ってもローカル環境での証明書とプロビジョニングプロファイルとの組み合わせは正しいのでipaファイルが生成できてしまいます。しかし、ローカル環境のプロビジョニングプロファイルにはApp Groupsに関する情報が含まれていないため、iTunes Connect(TestFlight)にアップロードするとエラーが発生してしまいます。

iOS Dev CenterのCertificates, Identifiers & Profilesで見るとInvalidになっているので確認することができます。再度、プロビジョニングプロファイルをGenerateしなおして、ローカル環境にインストールすれば問題は解決できます。