Java Build Failed in flutter application | Execution failed for task | Invalid source release | Flutter error fix 100%

Appblee
1
Execution failed for tast thumbnail

😊 Hi folks, I hope you're fine these days and you are here because I know you're on your way to finding how to fix the Java Build Failed error in Flutter Framework. Here I'm guiding you to fix the issue in the optimal way. Let's get started! First of all why this error message? Why you're getting this error message is in your Flutter application one of your packages or dependency requires a higher version of Java to execute the package.

Error Message ❌

        FAILURE: Build Failed with an exception.

        * What went wrong:

        Execution failed for task ':package_info_plus:compileDebugJavaWithJavac'.

        > error: invalid source release: 17

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

This is the error message you're seeing. So how do we fix this Java invalid source release error?

Step 1:

Go to this website and download download Java JDK 17 or higher.


Step 2:

After installing the Java JDK, check whether it was successfully installed or not. to check that, open Command Prompt (cmd) and type java --version command. 


Environment Variables


if you see this message, then you have successfully installed it. Otherwise, you're getting some message that says "Java is not recognized as an internal command" in cmd. Then you should set the Java JDK bin path to the environment variable and system variable. How to do that? Type "Environment Variables" in the search bar and open it.

Environment Variables


After that in the User variable window, you can find a path variable and double-click on it. After that find the Java JDK installation folder copy the path of the bin file and add it here. According to the below screenshot, it is the 2nd record. But the order doesn't matter. 


Environment Variables

In the same way, you should add the same path for the System variables also. After that add the JAVA_HOME variable in the System variable. (Not in the path)

Environment Variables

After that check the Java Version code in cmd again and make sure it is successfully added.

Step 3:
Open your Flutter project in Android Studio and configure the Java version for the project.

File ---> Project Structure ---> Select the path in your Java JDK 17 installed path.


Step 4:
After applying the correct Java JDK version for the Flutter project open the IDE. In my case, I open Visual Studio Code. Then inside the gradle.properties file add the below line. 

Open the file
android ---> gradle.properties

add this line (Path should be changed to your installed path)
org.gradle.java.home=C\:/Program Files/Java/jdk-17

We are telling our flutter project the project uses that JDK to run our flutter project.

Step 5:
Run the flutter project to check whether the error is solved or not. :)
Hooray! You're done! 🌻

I invite you to check the full video tutorial on YouTube and Subscribe and share more videos. 🎥


Follow me on Linkedin


Tags:

Post a Comment

1Comments

  1. Could not determine the dependencies of task ':photo_manager:compileDebugJavaWithJavac'.

    ReplyDelete
Post a Comment