Reputation: 901
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
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
Upvotes: 90
Views: 276859
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
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
Reputation: 9
In android/gradle.properties
add this:
org.gradle.java.home=C:/Program Files/Java/jdk-17
Upvotes: 1
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
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
Reputation: 656
Upvotes: 3
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
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
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
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
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 |
Upvotes: 47
Reputation: 5947
I had the same problem with React Native and I solved following the next steps:
Open Android Studio
File -> Open your project (select the android folder)
Wait for the gradlew finish the build process
Then Menu Build -> Rebuild project
Now you can compile npx react-native run-android
Upvotes: 3
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
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
Reputation: 43
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
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
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.
Upvotes: 15
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
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
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
Reputation: 136
You might want update your gradle version. Check the supported gradle <-> kotlin <-> java version on their page.
Upvotes: 0
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
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
Reputation: 341
FOUND IT ! No need to change your JDK version, follow the steps to resolve the issue:
That's it, i hope it will resolve your issue like it resolves mine.
Try it and give a feedback.
Upvotes: 11
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
Reputation: 23
Try this!
Remove package android
from the top of settings.gradle. This helped me out.
Upvotes: 1
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
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
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
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
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