I encountered the following compilation error in Android Studio of one of my Android project about current target JVM compatibility (or incompatibility), as shown in the screenshot message listing below:
I managed to fix the problem by ensuring the source and target are compatible, i.e. having the same Java version.
To fix the issue:
- In Android Studio, select File | Project Structure.
The Project Structure dialog box appears.
- Click Gradle Settings.
The Gradle dialog box appears.
- In the Use Gradle from combo box, choose 'gradle-wrapper.properties' file.
- In the Gradle JDK combo box, choose jbr-17 JetBrains Runtime version 17.
- Click OK to close all dialog boxes.
- In Android Studio, open the app's build.gradle file in the editor.
- Within the android construct, add in the compileOptions as shown in the listing below.
From this point on, compiling the app should not throw upany JVM target compatibility errors.