前提
androidStudioでの環境構築初学者向けの記事です。
20230418前後で起きる現象かと思います。
事象1
JetBranisからandroidStudioをupdateで更新。
更新後以下のようなエラーが出る。
エラーログ
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
- Variant 'javadocElements' capability com.android.tools.build:gradle:8.0.0 declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.0')
解決策1
https://developer.android.com/studio/intro/studio-config?hl=ja
javaのバージョンが合致していないことが問題のように見えたので、JDKのバージョンをEmbedded JDKに変更。
エラー時はJDKが1.8になっていた。おそらくデフォルト。
事象2
それでもコンパイル時に別のエラーが発生した
エラーログ:
メモできていなかったため、その時のログキーワードに引っかかった記事掲載
https://stackoverflow.com/questions/75263047/duplicate-class-in-kotlin-android
解決策2
記事の通りorg.jetbrains.kotlin.androidを1.8.0に変更
plugins {
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
それでも治らないのでkotlinCompilerExtensionVersionを1.4に変更
composeOptions {
kotlinCompilerExtensionVersion '1.4.0'
}
これで無事にエラーが解消し、ビルドが通るようになりました。
終わりに
最初わからないと特にハマるので同じようにハマった人がいれば手助けになればと思います。