はじめに.
この記事で書かれている問題は、QtCreatorが参照するXcodeのファイルが古かった可能性がありそうです..
一周回って、QtCreatorのバージョンアップで改善されるかもしれないです..
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an com.apple.security.device.camera key with a string value explaining to the user how the app uses this data.の対策
環境 |
---|
MaxOS , macOS Monterey バージョン 12.1 , チップ Apple M1 |
Qt 5.15.2 |
QtCreator 4.15.1 |
アプリ実行デバイス, MacOS (Desktop) |
QtでCameraのExampleプロジェクトを探していたところ、下記のプロジェクトを発見。ビルド→実行しようとしたが、実行時にクラッシュしてしまうためいくつかの対策を施し実行できるようになったため、備忘録的に書いた記事です。
カメラの処理をしていそうなサンプル内のコード
Camera {
videoRecorder.audioEncodingMode: CameraRecorder.ConstantBitrateEncoding;
videoRecorder.audioBitRate: 128000
videoRecorder.mediaContainer: "mp4"
}
まず、普通に実行しようとしたところ、アプリ実行と同時に落ちる..
クラッシュログが表示されていて、クラッシュの種類が、SIGABRTだったためどこかで何かが足りず落ちていそう..
こんな感じ. (正確には、NSCameraUsageDescriptionとNSMicrophoneUsageDescriptionがあるけどcom.apple.security.device.cameraがなかった時のもの)
com.apple.security.device.cameraは機能を使用する時に、ユーザーへ提供される説明の文章(String)
調べていくと、Qtがデフォルトでxcode projectに同梱してくれる info.plistに必要な記載がないことがわかった.
そのためプロジェクトでinfo.plistを準備して、QMAKEの変数としてinfo.plistを渡すように.
info.plist
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>VidioCapture</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.asck.VidioCapture</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<!-- 追加分 --->
<key>NSCameraUsageDescription</key>
<string>This App require camera permission for video capturing</string>
<key>NSMicrophoneUsageDescription</key>
<string>This App require microphone permission for video capturing</string>
<key>com.apple.security.device.camera</key>
<string>This App require camera permission for video capturing</string>
<key>NSDockTilePlugIn</key>
<string></string>
</dict>
</plist>
QMAKEで、作成したinfo.plistのパスをQMAKE_INFO_PLISTに指定する
アプリ.pro
macx {
message("macosx build")
QMAKE_INFO_PLIST = $$PWD/macx/Info.plist # パスが自分が追加した場所で書き換える。
}
.proまで書き換えたら、一度ビルドで生成されているフォルダを削除しておきましょう
下記のフォルダ(ビルドフォルダ)を削除
準備ができたら実行してみる
実行してもまだクラッシュログで下記の内容のクラッシュログが出る場合
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an com.apple.security.device.camera key with a string value explaining to the user how the app uses this data.
===> まず試してみること。
出力されている、アプリ.app(名前はプロジェクト名で異なる)を直接実行できるかどうか
実行できない場合
おそらく、アプリ.appに設定されている、info.plistがおかしい (必要なkeyがないなど)
→試すこととしては、ビルドフォルダを消して、リビルド、もう一回ビルドなどを試してみる
→もしくは、アプリ.app内にあるinfo.plistを直接編集して正しいものにする
実行できる場合 (Qt Creatorのデバッグ(/Release)実行のみ実行できない)
おそらく、QtCreatorがにもcom.apple.security.device.camera が要る?
設定>設定項目> カメラ、フルディスクアクセスににQtCreatorがあればチェックを入れる(筆者は、カメラの項目にQtCreatorを見つけられなかった)
それでもダメな場合は、QtCreator.appに内包されている、info.plistを編集する
com.apple.security.device.cameraと、This App require camera permission for video capturingを追加
以上でやっと実行できるようになりました。
正直、QtCreator.appのinfo.plistまで編集するんか.. と思っていますが、QtCreatorのバージョンも4.15.1と古いので、もしかしたら、QtCreatorをアップデートすることで改善されるかもしれません。ただ趣味でやってるタスクの範囲なので適当に対応しました。
(現在は、QtCreator7のrcがでていて、QtCreator 6.0.2が安定版とされていますが、QtCreator 6の動作が怪しすぎるので、現行だとQtCreator 5.0.2をお勧めします)