If you are using latest JDK to your project then you can make changes in build.gradle(app-level) and your project will run successfully.
compileOptions {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
and
kotlinOptions {
jvmTarget = '21'
}