Flutter HealthKit導入するとXcodeでビルドエラー 解決方法は?

Flutter HealthKit導入するとXcodeでビルドエラー 解決方法は?

突然のBuild Failedが発生!

かれこれもう2ヶ月くらい前から、実機で動作確認が出来ていません。

ある日突然Xcode側で「Build Failed」となり、実行出来なくなりました。

Runner
warning build: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.
warning build: Run script build phase 'Thin Binary' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.
health
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:294:34: error build: 'HKAudiogramSensitivityPoint' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:297:53: error build: 'hertz()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:298:33: error build: 'decibelHearingLevel()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:301:40: error build: 'HKAudiogramSensitivityPoint' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:305:24: error build: 'HKAudiogramSample' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:312:25: error build: 'HKAudiogramSample' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:315:25: error build: 'HKAudiogramSample' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:449:48: warning build: Expression implicitly coerced from 'String?' to 'Any'
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:450:46: warning build: Expression implicitly coerced from 'Double?' to 'Any'
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:452:42: warning build: Expression implicitly coerced from 'Double?' to 'Any'
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:465:44: error build: 'HKAudiogramSample' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:471:90: error build: 'hertz()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:472:109: error build: 'decibelHearingLevel()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:473:111: error build: 'decibelHearingLevel()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:580:68: error build: 'decibelAWeightedSoundPressureLevel()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:593:50: error build: 'decibelHearingLevel()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:594:34: error build: 'hertz()' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:615:50: error build: 'discSports' is only available in iOS 13.0 or newer
/Users/[ACCOUNT]/.pub-cache/hosted/pub.dartlang.org/health-4.1.1/ios/Classes/SwiftHealthPlugin.swift:645:53: error build: 'fitnessGaming' is only available in iOS 13.0 or newer

原因を切り分けした結果

ググっても有力な解決方法は記載されていなかったので、原因は何かと調査していきました。

まずやってみたのが、Flutterプロジェクトを新規作成してみて、デフォルトのサンプルプログラムが動作するかどうか。

結果は正常にビルド出来、実機で動作しました。

次に、自分のブログを参考にしつつHealthKitを導入してみると、「Build Failed」となり、ビルドできなくなりました。

iOSのアップデートをした記憶はないような気がするのですが、iOSのアップデートにより、よりセンシティブになったのかもしれないなーと思いました。

やはり「HealthKit」が原因という結果となりましたが、これが分かっても解決方法がわからない…

これ以降、有効な対策がわからず迷走し、1ヶ月以上過ぎてしまいました。
もう健康系アプリを作るのを断念し、別のアイデアを考え始めていました。

最後の決意で解決策を探す

開発のリミットも迫る中、もう一度トライして解決しなかったら諦めようと決心し、ググって調査したところ、一筋の光を見つけました。

それはこのサイトのこの記事です。
未経験で始めるプログラミング【Error】’xxx’ is only available in iOS 13.0 or newer

エラー表示箇所をクリックすると解決方法が出てくるので、「Add @available attribute to enclosing class」を「Fix」すると解決するのだとか。

これを試すと一気に真っ赤っかになっていたエラーが取れました!
サイトの著者りゅうさんありがとう!

エラー箇所の赤いアイコンをクリックします。

次に「Add @available attribute to enclosing class」の「Fix」をクリックします。

すると、なんということでしょう!真っ赤っかだったエラーだらけの画面が一気に正常化したではありませんか!

そしてビルドをしてみると。。。

キタ━━(゚∀゚)━━!!!!ビルド成功!

これで開発再開できるようになりました。

まとめ

HealthKitを入れるとBuild Failed「’〜’ is only available in iOS 13.0 or newer」とビルドエラーになった時の対処法をご紹介しました。

エラー表示箇所をクリックすると解決方法が出てくるので、「Add @available attribute to enclosing class」を「Fix」すると解決するというものでした。

解決方法をシェアしてくださっていたりゅうさん本当に感謝いたします。

しかも調査の最中にAndroid版でのヘルスデータ取得方法が詳しく解説されているサイトも発見!

開発が大きく前進しそうです!

About The Author

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA