Could not create an instance of type org.gradle.invocation.DefaultGradle - flutter

I'm unable to build and run my flutter project. Every time I run the project it gives me this error
FAILURE: Build failed with an exception.
What went wrong:
Could not create an instance of type org.gradle.invocation.DefaultGradle.
Could not configure services using GradleScopeCompileServices.configure().
I searched and tried the following solution but nothing has worked so far:
Clean & Build Project
Deleted .gradle & .dart_tools folder
Downgraded Gradle version
I'm using Android studio 4.2.1. Let me know if you need anything else. Thanks in advance!

I tried many solutions but the following worked for me:
Downgraded flutter version from 2.2.3 to 2.2.2
Deleted ~/.android folder and then run the flutter project. Everything worked just fine.

I am use Flutter 2.5, same issue.
set ./android/build.gradle file to newer version:
classpath 'com.android.tools.build:gradle:7.0.0'
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Related

FAILURE: Build failed with an exception. in Flutter project

Hello I am new to flutter , and I have this error while trying to run my project.
Can someone help me with it ?
Thank you.
If faced same issue, this solution worked for me
In android/build.gradle file:
in buildscript change the following:
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
and in android\gradle\wrapper\gradle-wrapper.properties file:
add this line:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

I am trying to run my flutter app and I get this error every time , just upgraded flutter to 2.10.0 version [duplicate]

In Stripe, my client wants email and cardholder name, but the Stripe payment UI doesn't provide that option in com.stripe.android.view.CardMultilineWidget. I wanted to give it a try with the latest stripe version,
I was using Stripe version (14.1.1). So I updated it to the latest one (16.8.0)
The build showed me the error that it doesn't take minSdkVersion 19. It requires 21 in manifest merger. So I updated minSdkVersion to 21.
I got
caches/transforms-2/files-2.1/4541b0189187e0017d23bbb0afebd16a/jetified-kotlin-stdlib-common-1.5.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
I tried changing the Gradle version, but I am still getting the same error. How can I solve the incompatible error and add the email and cardholder name in Stripe?
Changing this in file build.gradle solved my problem.
From
ext.kotlin_version = '1.3.50'
to
ext.kotlin_version = '1.6.0'
Or whatever the latest version of Kotlin available and make sure to update Kotlin version on Android Studio as well.
I had this problem in a Flutter project.
In my case, a line for kotlin-gradle-plugin was missing in the Android build.gradle file, so adding ext.kotlin_version = '1.6.10' didn’t fix it.
After adding
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
the error was gone.
Full code section:
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Although this question has been answered, I think it's worth explaining what is happening
For the example:
The binary version of its metadata is 1.7.1, expected version is 1.5.1.
The expected version is the Kotlin for kotlin-gradle-plugin
The binary version is the what is downloaded (or previously compiled)
for com.android.tools.build:gradle
<project_dir>/android/build.gradle
buildscript {
ext.kotlin_version = '1.5.20' // <= expected version is 1.5.1
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1' // downloads 1.7.1 Metadata
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // <= 1.5.20 used here
Why is this Happening So Much?
The user updates the Kotlin version of the plugin to match the IDE version per the warning.
The user updates the android build tools gradle plugin per the warning
This is the WRONG version!
Now you don't have any warnings, but the version suggested is 7.1.3 which is not the latest. (I don't know why it suggests this older version) 7.3.1 is currently the latest and is meta data 1.7.1, so it will match the Kotlin version of 1.7.20 (which is also metadata 1.7.1)
What else could be wrong?
Due to caching, gradle may be using an older dependency before you updated. To start clean:
delete the ~/.gradle/cache directory
delete the android/.gradle directory
delete the project_dir/build dir
ensure the android/gradle/gradle-wrapper.properies has the correct distributionUrl (currently distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip)
from project_dir do flutter build apk
NOTE: your dependencies may need to be updated if their com.android.tools.build:gradle version is too old. Alternatively, both the kotlin and tools:gradle versions can be downgraded to compatible version that match metadata (although Android Studio will warn for that not matching the IDE Kotlin version)
How to Prevent this from happening Again?
Use the same Kotlin version as the IDE normally for ext.kotlin_version. see https://kotlinlang.org/docs/releases.html#release-details
Double check the com.android.tools.build:gradle version. See https://developer.android.com/studio/releases/gradle-plugin#updating-gradle and https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
If you are facing this error in Flutter build for Android then try to change the Kotlin version to
ext.kotlin_version = '1.4.32'
Firstly, go to settings, and then navigate to plugins. Find the Kotlin plugin and update it.
Next, in gradle files, go to build.gradle (Project: YourApp). Then, change the following code (in buildscript) from:
ext.kotlin_version = '1.3.50'
to the latest version, such as:
ext.kotlin_version = '1.4.32'
To know the latest version, go to settings and the plugins, find the Kotlin plugin, and make sure it is updated. The latest version is under JetBrains.
After following the instructions, your error will be resolved.
Make sure that the Kotlin version of your IDE is the same as the version declared in your gradle.build file.
It was fixed by updating the Kotlin Gradle plugin version.
In the project level build.gradle file, update the following line.
ext.kotlin_version = '1.6.10'
You can find the latest Kotlin Gradle plugin version at
Tools / Build tools / Gradle.
Changed the Project build gradle to
buildscript {
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
What do you need to to solve this?
I was facing this issue since last night. Just navigate through some webpages couldn't get to the exact solution. I finally solved it by these steps:
Replace ext.kotlin_version = '1.3.50' with ext.kotlin_version = '1.4.32' in the build.gradle file.
Clean project → Build the project with Gradle files → Run
in my case for
The binary version of its metadata is 1.7.1, expected version is 1.5.1
got to (dependencies) inside build.gradle(project) convert from 1.5.x (x) in my case is (20)
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
to 1.7.10
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
Another solution is to downgrade androidx.core:core-ktx library to any compatible version. This one worked for kotlin_version = '1.3.31':
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1' // The only working for this version (sdk/gradle)
implementation 'androidx.core:core-ktx:1.0.2' // The only working for this version (sdk/gradle)
implementation 'androidx.constraintlayout:constraintlayout:1.1.2' // higher versions require min-sdk >= 26
...
}
Android SDK: compileSdkVersion 30 and minSdkVersion 19.
Gradle build Tool: com.android.tools.build:gradle:3.3.1.
Just go to file build.gradle (Project: yourProjectName).
Change
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.5.x' apply false
...
}
(1.5.x means x version number at your case, such as 1.5.1.)
To
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...
}
It works in my case...
Most of the answers here seem to revolve around projects that use Gradle.
I randomly encountered this problem in IntelliJ IDEA that that was compiling and running a Maven project just fine 5 minutes before - no configuration changes. I introduced a new exception class and this problem popped up.
I tried invalidating caches and restarting, which didn't resolve the issue - however, disabling and re-enabling the Kotlin plugin resolved the issue.
Using Flutter, it was fixed by:
Updating Android Studio packages, specially the Kotlin plugin.
Get the last Kotlin plugin version Nbr from Gradle - Plugin and versions. For now it's 1.6.10.
Update <Your_project_name_folder>\android\build.gradle file by replacing the old Kotlin version by the new one you got from the web site above.
ext.kotlin_version = '<The_new_version_Nbr>' in my case ext.kotlin_version = '1.6.10'
Restart Visual Studio Code.
You're done.
Go to the file build.gradle, change the version of kotlin.
In case in my flutter project I opened build.gradle and changed
`ext.kotlin_version = '1.5.30'`
to
ext.kotlin_version = '1.6.0'
Here
buildscript {
ext.kotlin_version = '1.6.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Then save and do
flutter clean and flutter run.
Works fine for me.
I faced the same problem in Flutter and I fixed it by going to:
File > Settings > Plugins as #Muzzamil said and I checked for the version of Kotlin in my IDE and simply replaced the value in ext.kotlin_version (that is 1.6.10) by that value
ext.kotlin_version = '1.6.10'
project build.gradle:
ext.kotlin_version = '1.6.10'
app/build.gradle:
dependencies {
// classpath 'com.android.tools.build:gradle:7.1.2'
// classpath "org.jetbrains.kotlin:kotlin-gradle- plugin:$kotlin_version"
}
But after changes ext.kotlin_version to lower this warning stay but the red warning is gone
For macOS you can
rm -r $HOME/.gradle/caches/
or you can invalidate caches
File >> Invalidate caches
I have the set minsdk 24 and restart the Android Studio, its working fine.
This works for me
buildscript {
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
solution
A failure occurred while executing com.android.build.gradle.internal.tasks
Please check if you Kotlin version is compatible with compose version.
if not, then please make the changes and it should work fine.
Compose Compiler Version Compatible Kotlin Compiler Version
1.3.0 --> 1.7.10
1.3.0-rc01 --> 1.7.10
1.3.0-beta01 --> 1.7.10
1.2.0 --> 1.7.0
1.2.0-rc01 --> 1.6.21
1.2.0-beta03 --> 1.6.21
1.2.0-alpha08 --> 1.6.20
1.1.0 --> 1.6.10
1.1.1 --> 1.6.10
1.1.0-rc031.6.10
I upgraded the android studio version to the latest and that resolved the issue
I have faced this error in IntelliJ IDEA with a Maven project.
The solution is about to turn off Kotlin plugin in IntelliJ IDEA if you are not using Kotlin in your project.
Go to:
Menu File → Settings → Plugins
And turn off the Kotlin plugin by click on the checkbox. See here:

Getting compile time error in audioplayers dart package

I am new in flutter and I followed londonappbrewery course, in that course she teach us to use audioplayers packages so I follow her and import it on pubspec.yaml but when I want to run my flutter app it give this error. Please give solutions I am running it on physical device with Android 10. This is the error.
Can you try the following and please make sure that you have an Android project setup with Kotlin,
This file ensures that the Android project is using Kotlin android/app/src/main/kotlin/com/example/your_app/MainActivity.kt
In android/build.gradle
buildscript {
ext.kotlin_version = '1.5.10' // Update this version or add this line
...
dependencies {
...
// Make sure this line is here
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
In android/app/build.gradle make sure this line is there too at the bottom,
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
In android/gradle/wrapper/gradle-wrapper.properties use updated gradle version gradle-6.5-bin.zip for distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
If any confusion or question please leave a comment.
I think it might solved by changing the following line in the build.gradle from:
ext.kotlin_version = '1.3.50'
To
ext.kotlin_version = '1.4.32'
…or whatever the latest version of Kotlin available is. Make sure to update your Kotlin version on Android Studio as well.

Error while cloning flutter project from Github

I am trying to clone the following Flutter project from Github.
https://github.com/rxlabz/flutter_dropcity
But I am getting the following error in build.gradle using VS Code terminal.
What went wrong: A problem occurred evaluating root project 'android'.
A problem occurred configuring project ':app'.
Failed to notify project evaluation listener.
com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
Please help me out here. Thanks in advance!
It seems from the discussion at https://github.com/flutter/flutter/issues/10236 that the problem can be fixed with using a newer build version.
For this go to build.gradle file in Android/gradle folder. Now change android build.gradle version from 2.2.3 (as in the original github repo) to 2.3.3 like so:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}

Gradle Scala Plugin - how to specify zincClasspath

I am trying to use the Scala plugin with Gradle to build my project on an Ubuntu VM. This is what my build.gradle file looks like:
apply plugin: 'scala'
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.8'
}
when I run gradle build from the command line, I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':compileScala'.
> No value has been specified for property 'zincClasspath'.
I have looked around for where to specify this zincClasspath property, but can't find anything.
I have tried to force the zincClasspath to use an older version of the scala library, but it doesn't seem to work.
Any help is much appreciated
Edit:
One thing to add, this exact project builds fine on my local Windows machine, but not on my Ubuntu VM....
Fixed this myself in the end, the clue was that it was running on my Local machine but not my VM... of course my Gradle version was different.
Upgrading to Gradle 3.0 fixed this
I ran into this issue again recently, adding the following to my Gradle build script seemed to fix it:
ScalaCompileOptions.metaClass.daemonServer = true
ScalaCompileOptions.metaClass.fork = true
ScalaCompileOptions.metaClass.useAnt = false
ScalaCompileOptions.metaClass.useCompileDaemon = false