Same issue but after upgrading to Android Gradle Plugin 8.1.1 using the Upgrade Assistant and setting all compileOptions and kotlinOptions to use Java 18 (JavaVersion.VERSION_18, jvmTarget = "18"), the build now completes successfully. Looks like the issue is related to mismatched Java versions before the upgrade.