エミュレータではビルドできるけど、実機ビルドしたらエラーになった場合は、証明書を疑いましょう。
今回はエラーログに
unable to build chain to self-signed root for signer "..."
というのを見つけたので、Keychain Accessを開いてみると、 certificate is not trusted
というのを発見。
いつのタイミングでこうなっていたかは不明。
Xcodeの Manage Certificates...
を開いても Untitled
になっていて、なんか怪しい。
Apple Developerのサイトから該当証明書を削除します。
Keychain Accessに戻って、該当証明書を削除します。すると自動的に新しい証明書が作成されました。(前からこうだったけ?)
ということで、Xcodeからも証明書が新しくなったことが確認でき、無事実機ビルドが通りました。