エラー「One or more plugins require a higher Android SDK version.」を解決するの?|SDK|Flutter


Flutter SDK のバージョンをアップ(3.3.5 に)したら、こんなエラーが出たよ…。

---
Launching lib\main.dart on Pixel 7 in debug mode...
Running Gradle task 'assembleDebug'...
Warning: The plugin flutter_local_notifications requires Android SDK version 33.
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to C:\GomachoApp\android\app\build.gradle:
android {
  compileSdkVersion 33
  ...
}
---

使っているプラグインで、より高い Android SDK バージョンが必要ですって?!

このファイル「C:\GomachoApp\android\app\build.gradle」に記載の「compileSdkVersion」を「33」へ変更すれば良いだけだね!

…あれ?

開いたら「C:\GomachoApp\android\app\build.gradle」にはこう書いてある。

---
android {
  compileSdkVersion flutter.compileSdkVersion
  ...
}
---

どどど、どういうこと?


直し方

こう書いちゃってオッケー。

android {
  compileSdkVersion 33
  ...
}


… flutter.compileSdkVersion って?

flutter.compileSdkVersion」は Flutter SDK が定義しているデフォルトの数値を参照しているだけだよ。

定義されているファイルは「C:\Flutter\packages\flutter_tools\gradle\flutter.gradle」にある。

そしてこう書いてある。

---
/** For apps only. Provides the flutter extension used in app/build.gradle. */
class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 31
    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 16
    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 31
---

これを以下のように変更することもできる。

---
/** For apps only. Provides the flutter extension used in app/build.gradle. */
class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 33
    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 21
    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 33
---

けれども、この直し方は否定的な意見が多い印象。

何故ならば、こうすると開発環境のデフォルトが変わってしまって全てのアプリに影響してしまうから。

アプリ毎に「compileSdkVersion」は定義されるべきだ!って声が多いよ~。


関連


参考

コメント

このブログの人気の投稿

ImagePicker を操作すると「Lost connection to device.」とだけ言い残して強制終了するの?|iOS|Flutter

Android SDK バージョン(コンパイルに使用する Android API レベル)を変更するの?|compileSdkVersion|SDK|Android|Flutter