【Xcode/Swift】ビルドエラー対処法まとめ

wp_tmb_xcode-error-solution

最近(2020年4月)、Xcodeでのビルドは中々エラーが出る日々を送っています。

例えば、実機iOSを最新アップデートしないといけなかったり、デバイスにアプリが正しく接続されていないとかですね。。。

しかし、どれも自分なりにエラーを対処することが出来ました。

本記事では私が実際にXcodeで実機iPhoneにアプリをインストールしようとした時の対処法を示しています。

エラー内容一覧

  • エラー「This app could not be installed at this time.」
  • エラー「A build only device cannot be used to run this target.」

エラー「This app could not be installed at this time.」

Xcodeでビルドした時、次のエラーメッセージが出て、Simulator上でアプリを起動することができませんでした。

f:id:koshishirai:20200511082311p:plain

エラーメッセージ

This app could not be installed at this time.
Could not install at this time.
Could not hardlink copy A (/Users/ユーザー名/Library/Developer/Core Simulator/Devices/188C898E-AE35-4F8F-8325-E85EA93E7E66/data/Containers/Bundle/Application/B4C4FE2D-8E21-4341-BB3B-1B4AF28608F5/557 y 7.app)
to B (/Users/ユーザー名/Library/Developer/Core Simulator/Devices/188C898E-AE35-4F8F-8325-E85EA93E7E66/data/Library/caches/com.apple.mobile.installd.staging/temp.wM9luf/extracted/Payload/typy 7.app)
with manifest C (/Users/ユーザー名/Library/Developer/Core Simulator/Devices/188C898E-AE35-4F8F-8325-E85EA93E7E66/data/Library/Caches/com.apple.mobile.installd.staging/temp.wM9luf/extracted/com.apple.deltainstallcommands.com.開発者名.Swift5CountUp1)

日本語訳

現在、このアプリをインストールできませんでした。 マニフェストC.Swift5CountUp1を使用してA.appをB.appにハードリンクコピーできませんでした。

英語が長くて、日本語に翻訳しても意味が分かりにくいですね。。

Detalesをクリックして、詳細を見てみます。

f:id:koshishirai:20200511082353p:plain

先ほど違う箇所に注目しましたが、よく分からない???ですよね。

対処法「This app could not be installed at this time.」

このエラーの対処に当たっては、下記のサイトが参考になりました。

ios – Xcode 8.3.2 : Could not hardlink copy – Stack Overflow

  1. Xcodeを終了します。
  2. Simulatorを起動し、Hardware > Erase All Content and Setteings… にいきます。

option押しながら、クリックしてください。

f:id:koshishirai:20200505112003p:plain
  1. 次の画面が出ます。デバイスを初期化します。Eraseをクリックしてください。
f:id:koshishirai:20200505112024p:plain
Are you sure you want to erase content and settings?The device will be erased to its initial state.コンテンツと設定を削除してもよろしいですか?デバイスは初期状態に消去されます。
English日本語
  1. その後、Simulatorを終了してください。
  2. Xcodeを再起動&ビルド

無事解決です…!

解決するまでの過程「This app could not be installed at this time.」

まず、このサイトの対処法を試しました。

[Xcodeでビルドしようとしたら “This app could not be installed at this time.” というエラーが出て失敗する状態からの脱出 – Qiita](https://qiita.com/jshimazu/items/0616b4f0254f57c97a36)

> altを押しながらproduct > clean build Folder

しかし、この部分を実行しても、エラーは直せませんでした。

続いてこのサイトを試しました。

[【未解決】Xcodeの「This app could not be installed at this time.」エラーの対処法 – 株式会社シーポイントラボ | 浜松のシステム・RTK-GNSS開発](https://cpoint-lab.co.jp/article/202004/14679/)

1. シミュレーターをリセットする。
2. Simulatorを起動し、Hardware -> Erase All content and settings… を、optionを押しながらクリックします。

これでエラーが出なかったため、問題を解消できたかのように見えましたが、おかしいです。

下の画像のように、一部、不具合が出ました。

![f:id:koshishirai:20200505122422p:plain](https://koshishirai.com/wp-content/uploads/2020/06/20200505122422.png)

もう少しggってみました。

[This app could not be installed at this time. のエラー対応 – ObjecTips](http://koze.hatenablog.jp/entry/2019/04/15/090000)

より

〜/ Library / Logs / CoreSimulator /の中にあるログファイルを見れば良いとの事でした。

早速、Simulator.logを開きました。

![f:id:koshishirai:20200505122521p:plain](https://koshishirai.com/wp-content/uploads/2020/06/20200505122521.png)

Simulator.log

“`
Oct 28 20:15:39 AnoMacBook-Pro Simulator[629] <Error>: Pasteboard for device 188C898E-AE35-4F8F-8325-E85EA93E7E66 lost connection
Oct 28 20:22:32 AnoMacBook-Pro Simulator[982] <Error>: Pasteboard for device 188C898E-AE35-4F8F-8325-E85EA93E7E66 lost connection

Oct 28 21:04:12 AnoMacBook-Pro Simulator[2672] <Error>: Pasteboard for device 188C898E-AE35-4F8F-8325-E85EA93E7E66 lost connection
“`

英語:

Pasteboard for device 188C898E-AE35-4F8F-8325-E85EA93E7E66 lost connection

日本語:

デバイス188C898E-AE35-4F8F-8325-E85EA93E7E66のペーストボードが接続を失いました。

ようするに、デバイスにアプリが正しく接続されていないらしいことが分かりました。

エラー「A build only device cannot be used to run this target.」

  • 実機iOS12.4にアプリを入れるには実機を最新バージョンにしないとビルドできないよと表示されました。(2019.10.31時点)
  • 私は何が何でも実機iOS12.4でビルドしたかったので、試行錯誤したらなんとか実機を最新のiOSにアップデートせずにビルドすることができました。
  • 本記事では実機iOSをアップデートせずにアプリをビルドする対処法を示しています。
f:id:koshishirai:20200505112432p:plain

英語

A build only device cannot be used to run this target.
Please select only device or choose a simulated devices as the destination.

日本語訳

ビルド専用デバイスを使用してこのターゲットを実行することはできません。
デバイスのみを選択するか、シミュレートされたデバイスを宛先として選択してください。

ようするに、Xcodeから「実機iOS12.4を現最新iOS13.1にアップデートしなさいよ」と警告されます。

対処手順「A build only device cannot be used to run this target.」

ここでは実機 iPhone XS Max iOS12.4をアップデートせずにアプリをインストールしようと試みています。

  1. iOS13.1のプロジェクトをバックアップ用に複製します。(推奨)

プロジェクトフォルダを複製したり、ファイル名を変更するなどして下さい。

  1. iOS12.4のプロジェクトを新規作成します。
  2. Targets > General > Deployment Info Target へいきます。

ビルドしたいデバイス(ターゲット、実機)のOSバージョンに合わせて、今回はiOS12.4を選択します。

  1. Project > info > Deployment Info Target > iOS Deployment Target こちらもiOS12.4を選択します。
f:id:koshishirai:20200505122646p:plainf:id:koshishirai:20200505122615p:plain
34
  1. ビルドを実行すると、そのコードはios12.4で実行可能なSwiftのバージョンに対応していないため、エラーが起こります。

今回エラーが起こったファイルは、SenceDelegate.swiftとAppleDelegate.swiftです。

f:id:koshishirai:20200505122718p:plain
  1. SenceDelegate.swiftとAppleDelegate.swiftを全てFixします。
f:id:koshishirai:20200505122729p:plain

エラーがなくなるまで続けて、修正できない箇所があれば、コメントアウトします。

今回は、AppleDelegate.swiftにありました。

コメントアウト前

f:id:koshishirai:20200505122824p:plain

コメントアウト後

f:id:koshishirai:20200505122853p:plain

全部Fix出来たら、ビルドします。エラーが出ずにビルド出来たら成功です。

もし、実機でビルドが上手くいかない場合

f:id:koshishirai:20200505122926p:plain

画像の下のようにログに

エラーメッセージ

[Application]The app delegate must implement the window property if it wants to use a main storyboard file.

日本語

ファイルを使用する場合、アプリデリゲートはウィンドウプロパティを実装する必要があります。

と出た場合、Main.storyboard → AppleDelegate.swiftに次のコードを記述します。

これはウィンドウプロパティを使用するおまじないです。

var window: UIWindow?
f:id:koshishirai:20200505122950p:plain

これでもう一度、ビルドを試します。

私の場合、これでビルドに成功しました。これはビルドに成功した時の動画です。

qiita用【Xcode11.1, Swift】Deployment Target iOS13.1でも、実機iOS12.4でビルドする方法(図解)pic.twitter.com/gjdwpKKqCj

koshishirai (@koshishirai) November 1, 2019

最後に

  • 実機が iOS13.1でもiOS12.4でビルドする対処法を説明しました。
  • プログラミング講座通りに実施し、実機のOSのバージョンが異なっててあせりましたが、なんとかビルドに成功することができました。

参考

動作環境

  • macOS Mojave
  • Xcode Version 11.1 (11A1027)
  • iPhone XS MAX iOS12.4(実機)

koshishirai / 3D Modeler

Leave a Comment