【Kotlin/Android Studio】'compiledebugjavawithjavac' task (current target is 1.8) and 'kaptgeneratestubsdebugkotlin' task (current target is 17) jvm target compatibility should be set to the same java version. consider using jvm toolchainの解決法

この記事からわかること
- Android Studioでライブラリ導入時に発生したエラーの解決方法
- 'compiledebugjavawithjavac' task (current target is 1.8) and 'kaptgeneratestubsdebugkotlin' task (current target is 17) jvm target compatibility should be set to the same java version. consider using jvm toolchainとは?
index
[open]
\ アプリをリリースしました /
環境
- Android Studio:Flamingo
- Kotlin:1.8.20
'compiledebugjavawithjavac' task (current target is 1.8) and 'kaptgeneratestubsdebugkotlin' task (current target is 17) jvm target compatibility should be set to the same java version. consider using jvm toolchainの解決法
ライブラリを導入する際に「build.gradle(Module)」ファイルにコードを記述し「Sync Now」を実行したところ以下のようなエラーが発生しました。
'compiledebugjavawithjavac' task (current target is 1.8) and 'kaptgeneratestubsdebugkotlin' task (current target is 17) jvm target compatibility should be set to the same java version. consider using jvm toolchain
翻訳
「compiledebugjavawithjavac」タスク (現在のターゲットは 1.8) と「kaptgeneratestubsdebugkotlin」タスク (現在のターゲットは 17) JVM ターゲットの互換性は、同じ Java バージョンに設定する必要があります。 JVM ツールチェーンの使用を検討してください
原因
エラー内容を見る限りライブラリ導入時に実行されるタスクのJVM(Java Virtual Machine:Java仮想マシン)のバージョンが異なることが原因のようです。
解決法
「build.gradle(Module)」内のandroid {..}
内の以下の部分を変更することで解決することができました。
kotlinOptions {
jvmTarget = "1.8"
}
解決コード
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions {
jvmTarget = "1.8"
}
}
まだまだ勉強中ですので間違っている点や至らぬ点がありましたら教えていただけると助かります。
ご覧いただきありがとうございました。