skip to Main Content

Upgraded to Android studio Android studio 2024.2.1. Even did a fresh install.

Made a new Flutter project. When I run it, I get this error.

Launching libmain.dart on Pixel 8 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit 'C:UsersRokFlutter SDKflutterpackagesflutter_toolsgradlesrcmaingroovyapp_plugin_loader.groovy' 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 5s

┌─ 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                                                    │
│ C:UsersRokFlutterProjectsTesttest20241009androidgradlewrappergradle-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                               │
│                                                                                                 │
│                                                                                                 │
└─────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

Can run Android Java project without problems.

Tried a full uninstall and reinstall of Android Studio.

2

Answers


  1. This error occurs due to an incompatibility between the version of Java you’re using and the Gradle version specified in your Flutter project.

    Solution:
    Check the Java version Flutter is using
    Run the following command to verify the Java version being used by Flutter:

    flutter doctor --verbose
    

    Look for the Java version in the output.

    Update the Gradle version
    Based on the Java version from the previous step, you need to update your gradle-wrapper.properties file. This file is located at:

    <your-project>/android/gradle/wrapper/gradle-wrapper.properties
    

    Modify the distributionUrl to a compatible Gradle version. For example:

    distributionUrl=https://services.gradle.org/distributions/gradle-<compatible-version>-all.zip
    

    Replace with the correct version based on your Java version. You can refer to the compatibility table here.

    Sync and rebuild the project
    Once you’ve updated the Gradle version, sync your project in Android Studio to apply the changes. Then, run the following commands to clean and rebuild the project:

    flutter clean
    flutter pub get
    flutter run
    

    These steps should resolve the issue.

    Additional Resources:

    Login or Signup to reply.
  2. The same happened to me today, after installing Android Studio Ladybug 2024.2.1.

    As far as I understand, this is related to the new Java 21 version installed by AS.

    c:android-studiojbrbinjava.exe --version
    openjdk 21.0.3 2024-04-16
    OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    OpenJDK 64-Bit Server VM (build 21.0.3+-12282718-b509.11, mixed mode)
    

    Solution

    1. Update gradle-wrapper.properties

    C:project_pathandroidgradlewrappergradle-wrapper.properties

    distributionUrl=https://services.gradle.org/distributions/gradle-8.9-all.zip
    
    1. Update android/build.gradle to gradle:8.7.0
    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            THIS ->
            classpath 'com.android.tools.build:gradle:8.7.0'
        }
    }
    
    1. Update settings.gradle to gradle:8.7.0
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        
        THIS ->
        id "com.android.application" version "8.7.0" apply false
        
        id "org.jetbrains.kotlin.android" version "1.9.0" apply false
        id "com.google.gms.google-services" version "4.4.1" apply false
        id "com.google.firebase.crashlytics" version "3.0.0" apply false
        id 'com.google.firebase.firebase-perf' version '1.4.2' apply false
        id "com.huawei.agconnect" version "1.9.1.303" apply false
    }
    
    1. Update NDK in Android Studio if you get a build error like below
    A problem occurred configuring project ':fvp'.
    > com.android.builder.sdk.InstallFailedException: Failed to install the following SDK components:
          ndk;27.0.12077973 NDK (Side by side) 27.0.12077973
      Install the missing components using the SDK manager in Android Studio.
    
    1. Manually enter the new NDK (if required)
    android {
        namespace 'my app.com'
        
        compileSdkVersion 34
                            
        ndkVersion "28.0.12433566"
    ...
    
    1. Update libs (if required) ->

    pubspec.yaml

    audio_session: ^0.1.21
    chewie: ^1.8.5
    video_player: ^2.9.2
    just_audio: ^0.9.41
    just_audio_background: ^0.0.1-beta.13
    
    Execution failed for task ':audio_session:compileDebugJavaWithJavac'.
    
    1. Manually modify video_player_android (if required)
    c:Users<username>AppDataLocalPubCachehostedpub.devvideo_player_android-2.4.12androidbuild.gradle 
    
    see below link
    https://github.com/flutter/flutter/issues/148478#issuecomment-2358072537
    
    THIS -> def args = ["-Xlint:deprecation","-Xlint:unchecked"]
    instead do def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]
    
    THIS -> warningsAsErrors false
    instead of warningsAsErrors true
    
    Warnung: [options] Verwenden Sie -Xlint:-options, um Warnungen zu veralteten Optionen zu unterdrücken.
    Fehler: Warnungen gefunden und -Werror angegeben
    1 Fehler
    3 Warnungen
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':video_player_android:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    
    1. Build project
    flutter clean
    flutter pub get
    flutter run
    

    First build time may take longer (about 30 minutes for my project), so be patient.

    1. Sometimes you may need to manually delete old packages from cache c:Users<username>AppDataLocalPubCachehostedpub.dev

    2. You are done! Easy peasy!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search