error while building my apk on android studio

Project Settings

I am working on a Flutter project using Android Studio, and I am encountering issues during the build process. Specifically:

  1. Error Details:

    • When running the command flutter build apk --release, the build fails with the following error:

      FAILURE: Build failed with an exception.

      * What went wrong:

      Could not open cp_settings generic class cache for settings file 'D:\FlutterFlow\um_alqura\um_alqura\android\settings.gradle' (C:\Users\Aram\.gradle\caches\7.5\scripts\dbi4ru1b7c8lxo6ho27itx8jx).

      > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65

      * 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 2s

      Running Gradle task 'assembleRelease'... 3.2s

      โ”Œโ”€ Flutter Fix โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”

      โ”‚ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle. โ”‚

      โ”‚ โ”‚

      โ”‚ If you recently upgraded Android Studio, consult the migration guide at https://flutter.dev/to/to/java-gradle-incompatibility. โ”‚

      โ”‚ โ”‚

      โ”‚ Otherwise, to fix this issue, first, check the Java version used by Flutter by running flutter doctor --verbose. โ”‚

      โ”‚ โ”‚

      โ”‚ Then, update the Gradle version specified in D:\FlutterFlow\um_alqura\um_alqura\android\gradle\wrapper\gradle-wrapper.properties to be compatible with โ”‚

      โ”‚ that Java version. See the link below for more information on compatible Java/Gradle versions: โ”‚

      โ”‚ https://docs.gradle.org/current/userguide/compatibility.html#java โ”‚

      โ”‚ โ”‚

      โ”‚ โ”‚

      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

      Gradle task assembleRelease failed with exit code 1

    • This error points to an incompatibility between the Gradle version and the Java version being used.

  2. Environment Setup:

    • Flutter version: 3.24.2 (stable channel)

    • Dart version: 3.5.2

    • Android Studio version: 2024.2

    • Gradle version: 7.5 (default for the project)

    • Java version: Java 21 (bundled with Android Studio)

    • Android SDK: Platform 34, Build-tools 34.0.0

    • Operating System: Windows 10 (64-bit)

    ****

    • The error Unsupported class file major version 65 indicates that Java 21 (class file major version 65) is incompatible with the current Gradle version (7.5) in the project.

    • I want to use Java 17 instead, but Android Studio defaults to its bundled Java 21 runtime (C:\Program Files\Android\Android Studio\jbr\bin\java).

    The project still defaults to Java 21 due to the bundled runtime in Android Studio, causing the build to fail with the same error.

i need help to fix it

What have you tried so far?
  • Installed Java 17 and set JAVA_HOME to the Java 17 installation directory.

  • Updated gradle-wrapper.properties to use a Gradle version compatible with Java 21 (e.g., Gradle 8.2.1).

  • Configured android/build.gradle to use JavaVersion.VERSION_17 for both sourceCompatibility and targetCompatibility.

  • Cleared the Gradle cache and ran flutter clean before rebuilding.

Did you check FlutterFlow's Documentation for this topic?
Yes
1
1 reply