前人未踏の領域へ Androidアプリ開発編

Androidアプリ開発に関する調査メモ置き場。古い記事にはアプリ以外も含まれます。

Android:Android Gradle pluginを7.0.0-beta03にしたら同期エラーになった

課題

Android Gradle pluginのバージョンを 7.0.0-beta03 にあげたところ、Gradle project sysnc faildが発生した。 エラーメッセージは以下のとおり

Unable to find method ''void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)''
'void com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTests$default(com.android.build.api.extension.AndroidComponentsExtension, com.android.build.api.extension.VariantSelector, kotlin.jvm.functions.Function1, int, java.lang.Object)'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

対応

ググったところ、Hiltのバージョンを上げろという情報を発見。2.36 があったのでそちらに上げたところ無事エラーが解消された。

classpath "com.google.dagger:hilt-android-gradle-plugin:2.36"

Gradle Pluginのバージョン上げるならhilt-android-gradle-plugin も合わせて上げないといけないのかもしれない。今後は意識しよう。 もしかしたらkotlin-gradle-pluginも同様かも。

その後

結局Hiltのアノテーションコンパイルエラーでるようになったが、こちらは Kotlinのバージョンが 1.5.20-M1だったことが原因で、1.5.10にしたら落ち着いた。

結論

Arctic Fox Beta3 は以下のバージョンの組み合わせで動作することを確認

  • Kotlin 1.5.10
  • Gradle 7.0.0-beta03
  • Hilt 2.36

NG: 以下はだめ

  • kotlin: 1.5.20-M1
  • Hilt: 2.35.1

Jetpack Compose:こちらは1.5非対応なので

  • Compose: 1.0.0-beta07
  • kotlin: 1.4.32

参考

stackoverflow.com

dagger.dev

plugins.gradle.org