Skip to content

Flutter Android build errorFlutter: “Gradle task assembleDebug failed with exit code 1”

flutter run on Android stops with Gradle task assembleDebug failed with exit code 1. That line only says the Android build failed. The reason is printed above it: a Java version Gradle can’t handle, a broken build file, a plugin that needs a newer Android setup, or a missing SDK. Whatever the first error names is the one to fix. Here’s how to find it, in Gradle’s and Flutter’s words, or hand it over at a fixed price.

Short answer

Scroll up from the exit line to the first error, or run flutter run -v to see the full Gradle output. If it mentions Java or an unsupported class file version, run flutter doctor to see which Java is in use, and flutter analyze --suggestions from the project folder to check that Java, Gradle and the Android Gradle plugin fit together. If it points at a build file, run ./gradlew help in the android folder to check the build scripts on their own.

Find the real error, then fix it

  1. 01

    The exit line is a wrapper

    Flutter reports the Gradle task that failed, not why. The reason is a few lines above, after “What went wrong”. Run with -v for the whole log, or build from the android folder to see Gradle’s own output.

    flutter run -v
    
    cd android
    ./gradlew assembleDebug
  2. 02

    Java and Gradle don’t match

    “To find the Java version being used run flutter doctor.” Flutter, Android Java Gradle migration guide

    An Unsupported class file major version error means Gradle is too old for the Java that builds the app. Check which Java Flutter uses first, then let Flutter check the versions. The full steps are on the class file version page linked below.

    flutter doctor
    flutter analyze --suggestions
  3. 03

    JAVA_HOME points at the wrong place

    “You must ensure that a Java Development Kit version 17 or higher is properly installed, the JAVA_HOME environment variable is set, and Java is added to your PATH.” Gradle, Troubleshooting builds

    Gradle run directly, for example ./gradlew from the android folder or on a CI runner, uses JAVA_HOME. If the error says JAVA_HOME is set to an invalid directory, point it at an installed JDK. To choose the JDK Flutter itself uses, run flutter config --jdk-dir.

  4. 04

    A build file is broken

    “You can verify the problem with Gradle scripts by running gradle help, which executes configuration scripts but no Gradle tasks.” Gradle, Troubleshooting builds

    A bad edit to build.gradle, settings.gradle or gradle.properties fails every build the same way, even when ./gradlew --version works. Run gradle help through the wrapper to check the scripts without building.

    cd android
    ./gradlew help

Checked against the vendor’s docs on : Gradle User Manual: Troubleshooting builds; Flutter docs: Android Java Gradle migration guide.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Flutter unsupported class file major version · Flutter MissingPluginException · Flutter pod install failed · Expo EAS Build failed

Questions

More on this error

It builds in Android Studio but fails in the terminal. Why?

They can use different Java versions. Flutter builds with the Java bundled with Android Studio, or the one set with flutter config --jdk-dir, while ./gradlew run by hand uses JAVA_HOME. Run flutter doctor to see which Java Flutter uses.

Will flutter clean fix it?

Only when stale build files are the cause. Read the first error first; a Java, Gradle or build-file problem comes back after a clean.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.