Unknown Kotlin JVM target: 21" when I update Android Studio to a new version. Such that I updated to the new IDE "Nharwal" and got this issue.
Your Gradle JDK should be set to jbr-17 (JetBrains Runtime 17.0.14).
Update your Kotlin plugin version in the top-level build.gradle file.
Make sure that in your gradle.properties file, the property BuildConfig is set to true.
android.defaults.buildfeatures.buildconfig=true