'Error while trying to debug flutter app on physical android phone

I'm getting this error when I try to debug my flutter application on my android physical device .

This is my debug console output :

    Launching lib\main.dart on SM A515F in debug mode...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > One or more issues found when checking AAR metadata values:
     The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-28).
     Dependency: androidx.window:window-java:1.0.0-beta04.
     AAR metadata file: C:\Users\Administrator\.gradle\caches\transforms-3\598e97d118bac3af7420b509a0bba7ba\transformed\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.

     The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-28).
     Dependency: androidx.window:window:1.0.0-beta04.
     AAR metadata file: C:\Users\Administrator\.gradle\caches\transforms-3\39a13d14d6cfd824e114bd3c6574b2e2\transformed\jetified-window-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)


Solution 1:[1]

The error is on this line of the output

The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-28).

minCompileSdk must be lesser than compileSdkVersion. Correct it the build.gradle file (or inside the file showed in the error if the versions are right in the build.gradle) .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1