背景
flutterアプリをビルドすると下記warningが出るようになった
$ flutter run
building android...
💪 Building with sound null safety 💪
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.30/5fd47535cc85f9e24996f939c2de6583991481b0/kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.6.21/568c1b78a8e17a4f35b31f0a74e2916095ed74c2/kotlin-stdlib-jdk7-1.6.21.jar (version 1.6)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.6.21/11ef67f1900634fd951bad28c53ec957fabbe5b8/kotlin-stdlib-1.6.21.jar (version 1.6)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.6.21/5e5b55c26dbc80372a920aef60eb774b714559b8/kotlin-stdlib-common-1.6.21.jar (version 1.6)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.30/5fd47535cc85f9e24996f939c2de6583991481b0/kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.6.21/568c1b78a8e17a4f35b31f0a74e2916095ed74c2/kotlin-stdlib-jdk7-1.6.21.jar (version 1.6)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.6.21/11ef67f1900634fd951bad28c53ec957fabbe5b8/kotlin-stdlib-1.6.21.jar (version 1.6)
/Users/hoge/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.6.21/5e5b55c26dbc80372a920aef60eb774b714559b8/kotlin-stdlib-common-1.6.21.jar (version 1.6)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
Running Gradle task 'assembleRelease'... 131.8s
✓ Built build/app/outputs/flutter-apk/app-release.apk (51.3MB).
ビルド自体はできるものの何となく気持ち悪いので何か対策がないかと調べているとどうやらキャッシュを削除すればいいらしい
そこで下記コマンドでキャッシュを削除したがちゃんと記事を読んでいなかったので、エラーになっているフォルダだけでなくcacheフォルダを丸ごと削除してしまった。
$ rm -Rf /Users/hoge/.gradle/caches
その結果下記エラーでビルドができなくなってしまった。。。
$ flutter run
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':flutter_line_sdk:generateDebugRFile'.
> A failure occurred while executing com.android.build.gradle.internal.res.GenerateLibraryRFileTask$GenerateLibRFileRunnable
> /Users/hoge/.gradle/caches/transforms-3/3bcdaf5e019888e2b567be88bb46bb6f/transformed/androidx.fragment-r.txt
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':flutter_native_splash:generateDebugRFile'.
> A failure occurred while executing com.android.build.gradle.internal.res.GenerateLibraryRFileTask$GenerateLibRFileRunnable
> /Users/hoge/.gradle/caches/transforms-3/3bcdaf5e019888e2b567be88bb46bb6f/transformed/androidx.fragment-r.txt
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUILD FAILED in 45s
辛い・・・
解決方法
色々試すもNo Such File or Directoryのエラーメッセージが多発するように。。。
どうやら別のファイルから読み込んでいたファイルを削除してしまったので、ファイルを参照できずエラーになっているようだった
最終的には下記コマンドで.gradle関連を全て削除した後ビルドするとうまくいった
$ rm -Rf /Users/hoge/.gradle
$ rm -Rf /flutterプロジェクトのルート/android/.gradle
$ flutter run