Open In App

How to Run Gradle Build in Flutter?

Last Updated : 11 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Gradle is a tool that is used to automate tasks in android development. The Gradle build is one specific task that can be used to create APK files for your app. Often, the flutter run/build tasks don’t work as desired, and in those cases, cleaning and building the Gradle again can be helpful. There are two methods to achieve this,

  1. Through command line
  2. Through manual method

Running Gradle Build in Flutter through Command Line

Open the terminal at the root of your flutter project. Then we’ll need to cd into the android directory and run the command. You need to have JDK and JRE installed to run this. 

Note: If you get a path error, navigate and find your JRE, copy the 

JRE-path

 

Path, and open Environment Variables, then add it to the system path. Follow the steps given below

  • Find the JRE path. It is usually in the same directory where you have the Android SDK installed.
  • After copying that path, open Environment Variables by typing env in your search bar and click on Environment variables.
Environment-Variables

 

We will add a new system variable.

Adding-new-system-variable

 

  • After this, click on the “New” button under the system variables section, and a prompt will open up. Then, name it JAVA_HOME and paste the copied JRE path in the variable value.
Adding-variable

 

After this, run the following commands from the root of your flutter app project.

cd android

./gradlew clean build

This will run the Gradle build process for you. You might see a few warnings, but they’re fine as long as there’s no error.

Gradle-output

 

Command-output-continued

 

Running Gradle Build in Flutter through the Manual Method

You can also download the latest Gradle and replace it in the Gradle source location,

  • Download the required Gradle version from this fast mirror https://distfiles.macports.org/gradle/
  • Replace the .zip file in the Gradle source directory with the new file you downloaded. The source directory can be found in C:\Users\<username>\.gradle\wrapper\dists\<gradleversion>\<code>
gradle-version-download-path

 

That’s it. Now you can run the flutter run or build command with the new Gradle version. So that’s how we can run Gradle build in flutter and debug our apps.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads