飛ばしても良い前提
Flutterで2021年秋くらいに「Googleログイン」「カメラ」を使ったアプリを作りました。
研究目的で作っており、実験できればそれでいっか程度で作ったので、1年ほど放置していると、
- 私が使っていたGoogleログイン機能が脆弱性の問題から使えなくなった
- 新しいログイン方法に乗り換えようとする
- 新しいログイン方法を使うためにはcompileSdkVersionを上げないといけない
- compileSdkVersionを30から31に上げると連続でエラーが出た
エラーが出る状況
- Flutter cameraを使っている
- 環境が古い
と、エラーが出る状況が限られており、エラーの報告自体がネットに中々無かったので、今回はこの連続エラーとその解決策として実行したことをまとめた記事です。
1個目のエラー(Flutter Cameraバージョンが古かった)
エラー文
flutter error : Execution failed for task ':camera:compileDebugJavaWithJavac'
エラーの詳細ログを取り忘れましたが、このケースと同じかと思います
解決策
これはFlutterのCamera pluginのバージョンが古くて出ているっぽい。
pubspec.yaml
のcamera: ^0.9.2+2
をcamera: ^0.10.0+3
(現時点最新)に変更することで解決
最新版はここから確認してください。
2個目のエラー(ext.kotlin_versionのバージョンが古かった)
1個目の対応をしたら、エラー文が以下のように変化。
エラー文
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
(中略)
┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update C:\<project place>\android\build.gradle: │
│ ext.kotlin_version = '<latest-version>' │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
解決策
こちらに関しては解決策が具体的に出てて助かる。
Flutter Fixに書かれている通り、android\build.gradle
内のbuildscript
にあるext.kotlin_version
を最新に変更。
自分の場合、以下の感じ。
ext.kotlin_version = '1.7.20'
最新バージョンはここから確認可能。
3つ目のエラー
2個目の対応をしたら以下のように変化。次も具体的対応策が提示されてて助かる
エラー文
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\<プロジェクトの場所>\android\app\build.gradle' line: 25
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'kotlin-android'.
> The current Gradle version 6.7 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.7.1 or newer, or the previous version of the Kotlin plugin.
(中略)
┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project needs to upgrade Gradle and the Android Gradle plugin. │
│ │
│ To fix this issue, replace the following content: │
│ C:\<プロジェクトの場所>\android\build.gradle: │
│ - classpath 'com.android.tools.build:gradle:<current-version>' │
│ + classpath 'com.android.tools.build:gradle:7.1.2' │
│ C:\<プロジェクトの場所>\android\gradle\wrapper\gradle-wrapper.properties │
│ : │
│ - https://services.gradle.org/distributions/gradle-<current-version>-all.zip │
│ + https://services.gradle.org/distributions/gradle-7.4-all.zip │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
解決策
Flutter Fixで指示された通り、
-
\android\build.gradle
の中のbuildscript
の中のdependencies
の中を以下のように変更
classpath 'com.android.tools.build:gradle:4.1.0'
↓
classpath 'com.android.tools.build:gradle:7.1.2'
-
\android\gradle\wrapper\gradle-wrapper.properties
を以下のように変更
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
↓
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
終わった
ここまで対応してアプリを走らせてみると、えっぐい量の文字化け赤字が出てきましたが、アプリ自体は動きました。なんでや。
写真は赤文字の一部で、実際はこの10倍くらい出ています。
でもここ以降はまた別の問題っぽいので、記事としては以上で終わり。