I had a similar issue with not being able to set it via studio so the easiest way
- Download jdk separately.
- Configure my project to use 17
- flutter config --jdk-dir yourJDK path
- Optionally (Some plugins may require) update
- sourceCompatibility JavaVersion.VERSION_17
- targetCompatibility JavaVersion.VERSION_17
- jvmTarget = '17'