Android studio having fun of me with Gradle version - gradle

I have just updated Android Studio to 0.4.2, and the first time I launched it I got an error saying:
Failed to refresh Gradle project 'MyProject'
Gradle version 1.8 is required. Current version is 1.9. If using the gradle wrapper, try editing the distributionUrl in /home/alex/gradle/wrapper/gradle-wrapper.properties to gradle-1.8-all.zip.
Please fix the project's Gradle settings.
The fun fact no. 1 is that the specified path doesn't exist - anyway, I have changed the distributionUrl in gradle-wrapper.properties in my project to 1.8, and relaunching Studio now asks for 1.9!
Any ideas on how I can fix this?
SOLUTION
Solved this by deleting the gradle folder. It downloaded the libs and solved the dependencies on its own.

Android Studio version 0.4.2 wont work with Gradle 1.8 you have to use gradle 1.9
Check following things :
1.inside every build.gradle file in your project the gradle dependency should look like.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
2.If you are using Local Distribution change the path from File>Settings>Compiler>Gradle and point it to gradle 1.9.
Change the path in gradle-wrapper.properties to
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-bin.zip

Related

Is there any way to create a new flutter project with upgraded gradle version?

I am using android studio for flutter project. Every time when I create flutter android studio says a new gradle version is available. So then I have to change it manually to new version. The problem is when I try to run app , it will download to new version. If I do not change it some plugins gives an error work with the old version.
This my build.gradle file.
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' //here I have to change it to 3.5.1
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}...
I tried to upgrade flutter,dart,android studio,gradle. But it does not work. If I create a new android project , it was created with new version. So how to create a new flutter project with upgraded gradle version?
You can't. The Gradle version is hard coded to flutter app's template (the same for the kotlin version). Typically a flutter version is also not guaranteed to be compatible with the latest gradle version, so maybe stick with the version from the template until you are sure it's compatible.
try gradle wrapper --gradle-version 7.2 on the terminal.

Gradle version 3.3 does not support forTask() method on BuildActionExecuter

I just updated my Android Studio to 3.0 canary 1.
Now I am working on my existing project on Android Studio 3.0 canary 1.
By default gradle:3.0.0-alpha1 is set in my project: gradle_file.
So I changed my gradle version to 2.2.3 and now I'm getting this error:
Error:Failed to complete Gradle execution.
Cause: The version of Gradle you are using (3.3) does not support the
forTasks() method on BuildActionExecuter. Support for this is
available in Gradle 3.5 and all later versions.
I attached my gradle file here
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've just had the same issue. Fixed it by changing Gradle distributionUrl in "gradle-wrapper.properties".
Here is what I have configured:
#Wed Mar 22 16:13:58 BRT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
for more details
Offical video to help migaration
https://www.youtube.com/watch?v=oBsbI8ICYKg
see also comment below from #TmTron
Change in the file "gradle-wrapper.properties".
Put this line and Sync Project-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
This will work. For Check latest version services.gradle.org/distributions
After changed, Sync Project, Clean and Rebuild project once from Build menu.
This happened when trying to build debug apk.
SOLUTION: Update Gradle version to 3.5
Navigate to File -> Project Structure -> Project -> Gradle Version = 3.5
This works for Android Studio 3.0
Please follow the below steps:
Open your project in android studio
In Android menu, open gradle-wrapper.properties
Change the distribution url line with the below line
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Thats it. Build your project now.
Screenshot is attached for more understanding.
I resolved the issue by changinf distributionUrl in the following code in gradle-wrapper.properties file
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Once add these with Top level Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha9'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
We have two way to deal with it.
You can update your gradle's version from the early one to 3.5 version product;
Or,you can figure your gradle wrapper to 4.1 version.
All of the ways are both useful.
Only Change the gradle URL to
"distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip"
as follow image :
Open gradle-wrapper.properties
Replace:
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
With:
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Now sync project
Click here for more understand
put this code in gradle-wrapper.properties file and it will work with you
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

How to fix Gradle sync error in Android Studio 2.3?

How do I fix a Gradle sync error in Android Studio (latest version 2.3)?
This error occurs when the gradle version is not compatible. Please update your gradle version in project level build.gradle to 2.3.
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}

Why am I getting "unsupported version of Gradle" with the tutorials app in Android Studio?

When I try to import the tutorials app to Android Studio, I get this message:
The project is using an unsupported version of Gradle.
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
I’m new to Android Studio, and meter too. What’s the problem with Gradle?
I’m using Android Studio 1.0.1.
Android Studio 1.0.1 supports gradle 2.2.1+ and Android Gradle Plugin 1.0.0+
How to change the gradle version.
In your project you should have a folder gradle/wrapper.
Inside you will find the gradle-wrapper.properties file.
Change this line inside
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
How to change gradle plugin version:
In your project you should have a build.gradle file in the root folder.
Inside:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter() // or mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
Pay attention. Each module has a own build.gradle file. Inside you can override the default configuration.
More info here.
I too have faced this issue, To resolve this issue there are two things you need to try.
You need to remember exactly what version of gradle distribution url you were adding to your existing project.
if you didn't remember, you have to goto https://services.gradle.org/distributions/ and do trial and error. Add all versions to gradle distribution url like shown below.
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
only change the last version number 2.2.1-all to 3.5-all and so on.
In gradle-wrapper.properties, modify the gradle version. Change to a newer one. The reason is generally: gradle and JDK, different versions are not compatible. Change the JDK to the old version.

How to change the version of the 'default gradle wrapper' in IntelliJ IDEA?

I want to use Gradle 1.10 instead of 1.9. I cannot seem to find where to change this.
If I put this:
task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}
in my build.gradle and rebuild, it is built with Gradle 1.9 again (so nothing actually happens).
These seem to be all the settings: (and IntelliJ's help section about Gradle doesn't help at all :( )
The easiest way is to execute the following command from the command line (see Upgrading the Gradle Wrapper in documentation):
./gradlew wrapper --gradle-version 5.5
Moreover, you can use --distribution-type parameter with either bin or all value to choose a distribution type. Use all distribution type to avoid a hint from IntelliJ IDEA or Android Studio that will offer you to download Gradle with sources:
./gradlew wrapper --gradle-version 5.5 --distribution-type all
Or you can create a custom wrapper task
task wrapper(type: Wrapper) {
gradleVersion = '5.5'
}
and run ./gradlew wrapper.
Open the file gradle/wrapper/gradle-wrapper.properties in your project. Change the version in the distributionUrl to use the version you want to use, e.g.,
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
I just wanted to chime in that I hit this after updating Android Studio components.
What worked for me was to open gradle-wrapper.properties and update the gradle version used. As of now for my projects the line reads:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-all.zip
./gradlew wrapper --gradle-version=5.4.1 --distribution-type=bin
https://gradle.org/install/#manually
To check:
./gradlew tasks
To input it without command:
go to-> gradle/wrapper/gradle-wrapper.properties
distribution url and change it to the updated zip version
output:
./gradlew tasks
Downloading https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
...................................................................................
Welcome to Gradle 5.4.1!
Here are the highlights of this release:
- Run builds with JDK12
- New API for Incremental Tasks
- Updates to native projects, including Swift 5 support
For more details see https://docs.gradle.org/5.4.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Starting Daemon
You can set the version of Gradle generated by the wrapper task.
Note that this solution is in Kotlin DSL (build.gradle.kts).
Put this code in your top-level build.gradle.kts file:
tasks.wrapper {
gradleVersion = "7.4"
// You can either download the binary-only version of Gradle (BIN) or
// the full version (with sources and documentation) of Gradle (ALL)
distributionType = Wrapper.DistributionType.ALL
}
Whenever you want to change Gradle version:
Update the version above to your desired version
Execute Gradle wrapper task: ./gradlew wrapper
Sync the IDE (from Gradle sidebar -> reload icon)
I was facing same issue for changing default gradle version from 5.0 to 4.7, Below are the steps to change default gradle version in intellij
1) Change gradle version in gradle/wrapper/gradle-wrapper.properties in this property distributionUrl
2) Hit refresh button in gradle projects menu so that it will start downloading new gradle zip version
The 'wrapper' task in gradle is called if gradlew command is used, if you use gradle command to build the wrapper task is not called. So, there are two ways you can change your gradle version.
Use 'gradlew build' command, this command will call the wrapper task that you mentioned. That task will change the 'distributionUrl' parameter in gradle-wrapper.properties file and it will automatically download the gradle version you want. Example distributionUrl in the file for version 4.2.
distributionUrl=https://services.gradle.org/distributions/gradle-4.2-bin.zip
If you are not using gradle wrapper simply download the version of the gradle you want and set environment variable path and also show it to IDEA.
P.S. for more information about gradle wrapper I suggest you to read: https://docs.gradle.org/current/userguide/gradle_wrapper.html
In build.gradle add
wrapper { gradleVersion = '6.0' }
This question is really old, but current Intellij IDEA (Android Studio) have this in a dialog under:
Project Structure > Project > Gradle Version
First, let gradle set the correct distribution Url
cd projectDirectory
./gradlew wrapper --gradle-version 2.3.0
Then - might not be needed but that's what I did - edit the project's build.gradle to match the version
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Finally, delete the folders .gradle and gradle and the files gradlew and gradlew.bat. (Original Answer)
Now, rebuild the project.
As the other answers did not suffice for me and the comment pointing out these additional steps is easy to overlook, here as a separate answer
The easiest way to update the gradle in the intellij is, to remove the existing gradle folder in the project and automatically intellij will download the latest. For instance I had 6.41 as the downloaded version. I just removed this gradle folder and it automatically downloaded to 7.1. It might be helpful for someone..

Resources