93

I reinstalled my android studio since the sdk was not found and so on. After re installing java jdk and android studio , everything worked well until I got an error saying 'Could not initialize class org.codehaus.groovy.runtime.InvokerHelper' which I solved by changing the Gradle version. And now the error is 'Type 'FlutterTask' property 'assets' is missing an input or output annotation.'

FAILURE: Build failed with an exception.

  • What went wrong: Could not open settings generic class cache for settings file 'C:\Users\loran\ASProjects\xylophone-flutter\android\settings.gradle' (C:\Users\loran.gradle\caches\6.8.2\scripts\4mawlyb2l5e9tefyvnpxva1kg).

BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 60

  • 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 46s Exception: Gradle task assembleDebug failed with exit code 1

6
  • Can you do a ./gradlew clean and then open android studio and resync your gradle Commented Apr 24, 2021 at 9:31
  • @Sisir Where do I have to execute the command? In the IDE terminal didn't work for me. Commented May 12, 2021 at 17:40
  • The gradlew file is present inside your android folder. So open a cmd, navigate to ProjectRoot\android and then execute teh command Commented May 12, 2021 at 18:04
  • 6
    @Sisir gradlew clean and gradlew throws the same error Could not open settings generic class cache for settings file Commented May 12, 2021 at 18:13
  • setting java_home fixed error for me, org.gradle.java.home=/Applications/Android Studio 4.1 Preview.app/Contents/jre/Contents/Home Commented Nov 26, 2021 at 5:06

33 Answers 33

53

So the problem arises from inconsistency in the Java version installed on your machine, the default Java version configured on your android studio and the gradle version for your project. So building upon the answer given by Tafita Raza I fixed it following the steps below

  • Check your java version and remember it, use "java -version" in terminal
  • Go to your android studio path installation
  • In newer versions of android studio go to Andriod Studio/jbe while in older versions go to Android Studio/jre/ and edit the file named "release"
  • Replace the value of JAVA_VERSION with the version of Java installed on your machine if it's not the same as the java version on your computer
  • Now go into the project folder you are building and check if the Gradle version is compatible with the Java you have installed (latest table below, as of 2023-11-12)
Java version Support for compiling/testing/… Support for running Gradle
8 N/A 2.0
9 N/A 4.3
10 N/A 4.7
11 N/A 5.0
12 N/A 5.4
13 N/A 6.0
14 N/A 6.3
15 6.7 6.7
16 7.0 7.0
17 7.3 7.3
18 7.5 7.5
19 7.6 7.6
20 8.1 8.3
21 8.4 8.5
  • I had java 19.0.2 installed on my system so according to the table I need gradle version 7.6 to build a project. You can also check the official website gradle if your java version is not listed https://docs.gradle.org/current/userguide/compatibility.html

  • Go into your project_name/android/gradle/wrapper and edit the file gradle-wrapper.properties

  • Replace the distributionUrl with the version of gradle compatible with the java version on your system DistributionUrl Example

Sign up to request clarification or add additional context in comments.

9 Comments

Thank you! The compatibility table you provided was very useful. I had Java 17.0.6 and gradle 4.0.2. I updated gradle to 7.3.0 in my flutter project and now the app runs without problems.
Amazing! Thank you very much. Work perfect on my machine.
This was so on point. Thanks!!
Thank you , best response , the compatibility table is the key
The best solution so far.
|
37

I also had this problem So I did install java 8 You might have Java 13 So install Java 8

3 Comments

This didn't work for me. Where do I have to select the java edition?
It worked for me, I had the jkd 16 installed, so I installed the jdk 8 and worked. The Google needs free itself from all that envolves the java. It's so boring setuping all. Tks man!
installing JAVA 11 worked for me because I was using Kotlin 1.8.0
26

Java JDK 16 is the one that seems to lead to this issue try downgrading by downloading a lower version of JDK preferable JDK 8 or 11

To future individuals who will run to this error. Here is the link to download the JDK enjoy your coding experience don't forget to change the path too. https://www.oracle.com/java/technologies/javase-downloads.html

Comments

16

You can try this, It works for me.

Open the Android module to a new window and automatically download all necessary libraries after successfully building finished run the app.

enter image description here

2 Comments

Thank you, this worked 100% for me. You are a true savior.
I don't know why this works but isn't this something a project sync could have solved?
11

FOUND IT ! No need to change your JDK version, follow the steps to resolve the issue:

  • check your java version and remember it, use "java -version" in terminal
  • go to your android studio path installation
  • then in: Android Studio/jre/ open the file named "release"
  • take attention of the value of JAVA_VERSION field
  • if it's not the same as the java version on your computer, just change it with the version installed on your computer.

That's it, i hope it will resolve your issue like it resolves mine.

Try it and give a feedback.

6 Comments

I don't have a folder called jre
You can add a folder jre, and then copy the contents from jbr into the jre folder. Then reload your terminal before checking anything, like flutter doctor.
Didn't work. Same error.
bash: java: command not found
These instructions are not clear; I have an empty jre directory but I do have jbr directory
|
7

Try installing the latest Gradle package gradle-7.1.1, if you are using Java JDK 16 installed. To do this open android/gradle/wrapper/gradle-wrapper.properties file and under distribution url, update the gradle version to 7.1.1 (or the latest). After that, inside your Flutter project directory, run the following command in the terminal:

cd android && ./gradlew

2 Comments

gradle-7.4 for JDK 17
in my experience exploring this problem, if you upgrade jdk then you need to upgrade the gradle version too like this answer. But, you need to upgrade Android Gradle Plugin (AGP) too and that's where i stuck. Because, idk why server can't find AGP that compatible with gradel version. Everytime i search for the problem most answer is incompatible version of java, gradle, and agp. In the end i just back to old version.
7

I removed the JAVA_HOME path to the JAVA download and changed JAVA_HOME path to the following:

C:\Program Files\Android\Android Studio\jre

I am now coding

3 Comments

worked for me (or at least, moved me on to the next error :-p )
Just installed Studio Electric Eel | 2022.1.1 today. This worked for me, BUT, I had to use: \Program Files\Android\Android Studio\jbr (note: jbr instead of jre).
send your address, need to send some cookies and special thanks to @user1544428
5

mainly you have jdk16 i tried to install java 8 and set env to java 8 it worked for me

1 Comment

installing JAVA 11 worked for me because I was using Kotlin 1.8.0
3

In gradle wrapper.properties, change the code to this -

distribution Url = https://services.gradle.org/distributions/gradle-7.2-all.zip

In build.gradle, change the code to this -

classpath "com.android.tools.build:gradle:7.1.3"

And then, hit flutter run in terminal

Comments

3

I had the same problem with React Native and I solved following the next steps:

  1. Open Android Studio

  2. File -> Open your project (select the android folder)

  3. Wait for the gradlew finish the build process

  4. Then Menu Build -> Rebuild project

  5. Now you can compile npx react-native run-android

enter image description here

Comments

2

enter image description here

  1. Enter Android Studio > Contents
  2. Copy jbr folder
  3. Paste and rename jre
  4. flutter clean
  5. flutter run
  6. chill

2 Comments

Yours is the only method which worked. Also I kept my gradle in the path android/gradle/wrapper/gradle-wrapper.properties as distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
You didnt mention where to paste the copied folder.Is it in same folder or somewhere else?
2

In android/gradle.properties add this:

org.gradle.java.home=C:/Program Files/Java/jdk-17

Comments

1

Try this! Remove package android from the top of settings.gradle. This helped me out.

Comments

1

Simply go to your Android Studio path -> C:\Program Files\Android\Android Studio open jbr folder -> copy all files -> then go back -> paste all the files in the jre folder and "replace the files in the destination". It works for me in two different laptops. I have latest jdk version - 19.0.2

Comments

1

All you have to do is change the java version to 11 and provide JAVA_HOME to jdk 11. You need to ensure to delete any other java versions (latest). Then restart the system and it will work.

Comments

1

The full and final super-easy & latest solution of this problem is to create an environment variable with -

Variable - JAVA_HOME Value - C:\Program Files\Android\Android Studio\jbr

Comments

1

What worked for me was to add this line in {project}/android/gradle.properties

org.gradle.java.home=C:/Program Files/Microsoft/jdk-17.0.12.7-hotspot

I also changes JAVA_HOME to

C:/Program Files/Microsoft/jdk-17.0.12.7-hotspot

Comments

0

If this error occurs, this might because you have installed the latest JDK such as JDK 16. You download and install JDK 8 and uninstall JDK 16. Then restart the desktop/laptop and try launch and run flutter run again. It should be working fine.

1 Comment

installing JAVA 11 worked for me because I was using Kotlin 1.8.0
0

In my case, on Windows 10, my JAVA_HOME was set to JAVA SE 16 C:\Program Files\Java\jdk-16 and when I looked at the release file in java jre in android studio, C:\Program Files\Android\Android Studio\jre\release, I found that the the JAVA_VERSION WAS "11.0.10" (java 11) for short. So I changed the java installation on my PC to Java 11, update JAVA_HOME in my environment variables to point to the new java (C:\Program Files\Java\jdk-11.0.12) and restarted android studio, Then everything worked.

You can get your java 11 from here. https://www.oracle.com/java/technologies/javase-jdk11-downloads.html. Change 11 to 8, 16 etc to get the download link for the java version you need.

Comments

0

The problem has to do with having Java 13 or 16 installed on your computer. The current version of Flutter does not work with Java 13 and 16. Just uninstall either of these that you may have installed and installed Java 8 or Java 11. Restart your computer to effect the update. Everything should be fine afterwards

Comments

0

I got this error when using flutter. I fixed it ensuring the android-studio-dir path was set correctly. You set it up using flutter config --android-studio-dir="android studio path". Then run flutter doctor and ensure flutter can see Android Studio

Comments

0

In 'adnroid/gradle/wrapper/gradle-wrapper.properties' Change distributionUrl to version 7.0.1

In 'android/build.gradle' Change 'com.android.tools.build:gradle' to version 4.2.0

Comments

0

Java 11 is the only supported version by Flutter as for now. It compiles and installs. Previously I had this error using Java 19 and Java 8.

Comments

0

You might want update your gradle version. Check the supported gradle <-> kotlin <-> java version on their page.

Comments

0

The error message you're seeing is related to the flutter build process and it occurs when a required input or output annotation is missing from the assets property of the FlutterTask.

task buildFlutter(type: FlutterTask) {
// Add the @Input annotation to the assets property
@Input List<String> assets = ["assets/images/", "assets/fonts/"]

}

Comments

0

I had the same problem. Please make sure your jdk is compatible with your android studio/adroid sdk. In my case jdk 19 was not supported with android studio electric eel so i had to install jdk 17.

Comments

0

I resolve this using

sudo update-alternatives --set java /usr/lib/jvm/bellsoft-java8-amd64/bin/java

In my recents projects, I use:

sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java

for example, I created alias to change between

alias changeJavaTo1.8='sudo update-alternatives --set java /usr/lib/jvm/bellsoft-java8-amd64/bin/java'
alias changeJavaTo17='sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java'

Comments

0

change distribution url in gradle-wrapper.properties to latest distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

and module build.gradle classpath 'com.android.tools.build:gradle:7.2.0'

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

I uninstalled and installed Android Studio and created a new project through Android Studio and not through Visual Code, then I ran the command flutter build apk --split-per-abi through the IDE terminal and it worked without any problems.

Comments

0

I could not comment and thank @joseph-deweese and @tafita-raza due to less contribution but all credits to them.

Basically what i did was , I did not have /jre folder in /Android Studio , so created a new folder copied everything from /jbr folder and in the release file i updated the java version from 21 to 23 which I had installed in mine (check yours with java --version in terminal and replace)

Now add environment variable JAVA_HOME to this path i.e. C:\Program Files\Android\Android Studio\jre for me I think /jbr would also work but I am not touching my config again till the next error

EDIT - Better use Java 17 as of now

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.