![見出し画像](https://assets.st-note.com/production/uploads/images/101623562/rectangle_large_type_2_57effad11b87e30176c4599ac3cda589.png?width=1200)
[Flutter]unable to resolve class GradleExceptionの解決方法
Flutterプロジェクトで/android/app/build.gradleを開くと、unable to resolve class GradleExceptionというエラーが出ていました。
この状態でもビルドはできたのですが、放置するのは変なので調べてみました。
![](https://assets.st-note.com/img/1680214432591-FRKT8yb9t3.png)
![](https://assets.st-note.com/img/1680214448610-dhvoePf6CI.png?width=1200)
解決方法
こちらのGitHubで分かりやすく書かれていますが、
Android API 29以降のバージョンではGradleException()は対応しておらず、FileNotFoundException()に変更する必要があるそうです。
3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29
That's it! You should notice the Android API 29 Platform is now visible under External Libraries.
なので、/android/app/build.gradleのコードをこのように修正するとエラーが出なくなりました!
/// /android/app/build.gradle
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
ちなみに、自分のFlutterプロジェクトが使用しているAndroid APIのversionは、同じく/android/app/build.gradleから確認できます。
android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 31
targetSdkVersion 33
それぞれの単語の意味は、以下のとおりです。
minSdkVersion
アプリが正常に動作することが保証されている最低限のAndroid APIレベルを示す
targetSdkVersion
アプリがサポートする最新のAPIレベルを指定し、そのバージョンで動作する際に最適なパフォーマンスと動作を実現する
compileSdkVersion
アプリがコンパイルされる際に使用されるAPIレベルを示す