lorandsouza
lorandsouza

Reputation: 901

Could not open settings generic class cache for settings file '

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.

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

BUILD FAILED in 46s Exception: Gradle task assembleDebug failed with exit code 1

Upvotes: 90

Views: 276859

Answers (30)

Sahal
Sahal

Reputation: 19

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

Upvotes: 0

Muhammad Jawad Mansoor
Muhammad Jawad Mansoor

Reputation: 348

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

Upvotes: 1

Ahmed Abdelsattar
Ahmed Abdelsattar

Reputation: 9

In android/gradle.properties add this:

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

Upvotes: 1

Fernando Moura
Fernando Moura

Reputation: 1

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.

Upvotes: 0

Usman Hassan
Usman Hassan

Reputation: 51

The most reliable way to fix this issue is to make sure the jdk you installed is of the same version with your android studio's jdk.

I was on jdk 21, and my android studio is using jdk 17. I have to downgrade.

Upvotes: -2

Shahed Oali Noor
Shahed Oali Noor

Reputation: 656

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

Upvotes: 3

Amit Salvi
Amit Salvi

Reputation: 1

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'

Upvotes: 0

Lucas De Lavra Pinto
Lucas De Lavra Pinto

Reputation: 1388

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'

Upvotes: 0

murtaza Mustafa
murtaza Mustafa

Reputation: 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

Upvotes: 1

Bello Tomi
Bello Tomi

Reputation: 993

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 N/A
  • 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

Upvotes: 47

Vladimir Salguero
Vladimir Salguero

Reputation: 5947

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

Upvotes: 3

Ritika Bansal
Ritika Bansal

Reputation: 101

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

Upvotes: 3

Ayush Ranjan Rout
Ayush Ranjan Rout

Reputation: 1

I also had this problem So I just upgrade my flutter by the command flutter upgrade .

or You can Clean the Gradle cache: Similar to the previous error, you can try deleting the Gradle cache to resolve the issue. Navigate to the directory mentioned in the error message (C:\Users\loran.gradle\caches\6.8.2) and delete the scripts folder. Then, try rebuilding your project to see if the error is resolved.

Upvotes: -2

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.

Upvotes: 0

Laasya Krupa
Laasya Krupa

Reputation: 11

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.

Upvotes: 1

Yousuf Ali
Yousuf Ali

Reputation: 408

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

Upvotes: 15

YU WANG
YU WANG

Reputation: 1

Change the JAVA_HOME to your Android Studio root such as: D:\Android\Android Studio\jbr (not jre).

I don't change the java version, just changed the JAVA_HOME, it solved this question.

Upvotes: -2

Mirza Nawazish
Mirza Nawazish

Reputation: 1

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/"]

}

Upvotes: 0

Azam Ansari
Azam Ansari

Reputation: 11

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

Upvotes: 1

Lukas Heiligenbrunner
Lukas Heiligenbrunner

Reputation: 136

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

Upvotes: 0

anunezr
anunezr

Reputation: 59

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.

Upvotes: 0

Irfan Abdul ghaffar
Irfan Abdul ghaffar

Reputation: 1

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

Upvotes: 0

Tafita Raza
Tafita Raza

Reputation: 341

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.

Upvotes: 11

Edie Kamau
Edie Kamau

Reputation: 270

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

Upvotes: 0

Mahdi Bagheri
Mahdi Bagheri

Reputation: 23

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

Upvotes: 1

olasammy
olasammy

Reputation: 7406

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

Upvotes: 0

Samuel Nde
Samuel Nde

Reputation: 2743

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.

Upvotes: 0

Joseph DeWeese
Joseph DeWeese

Reputation: 71

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

Upvotes: 7

Eric
Eric

Reputation: 9

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.

Upvotes: 0

Anmol Tiwari
Anmol Tiwari

Reputation: 89

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

Upvotes: 6

Related Questions