I encountered this problem when we upgraded our Flutter project to JAVA_17 and Gradle 8.
In my case, the solution was just updating all the SDK Tools in Android Studio: