81

I am trying to use gradle build. It gives me error saying that

Failed to apply plugin [id 'com.android.library'] Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /home/sanjeewa/workspace/Android/UVCCamera/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip

But my gradle-wrapper.properties includes gradle-2.4-all.zip. I have changed it to gradle-2.2-all.zip Still same problem.

When I run gradle -version in terminal Gradle 2.10 shows as version.

How to solve that error??

my build gradle file is

 buildscript { 
   repositories { 
       jcenter() 
   } 
   dependencies { 
       classpath 'com.android.tools.build:gradle:1.3.0' 
   } 
 } 

 allprojects { 
   repositories { 
       jcenter() 
   } 
 } 
passsy
  • 5,162
  • 4
  • 39
  • 65
manitaz
  • 1,181
  • 2
  • 9
  • 26

8 Answers8

128
  1. Open gradle-wrapper.properties
  2. Change this line:

     distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
    

with

        distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
  1. Go to build.gradle (Project: your_app_name)
  2. Change this line

     classpath 'com.android.tools.build:gradle:XXX'
    

to this

     classpath 'com.android.tools.build:gradle:2.0.0-alpha3'

or

     classpath 'com.android.tools.build:gradle:1.5.0'
  1. Don't click Sync Now
  2. From menu choose File -> Invalidate Caches/Restart...
  3. Choose first option: Invalidate and Restart

Android Studio would restart. After this, it should work normally

Hope it help

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • Curios: why 2.0-beta3 instead of 1.5.0? – dsh Jan 12 '16 at 17:17
  • i am just using terminal to gradle build. I think no need to invalidate caches. – manitaz Jan 12 '16 at 17:18
  • @dsh `1.5.1` is the latest stable, but 2.0-beta3 works fine, it's a bit faster. I'm already using AS 1.5 stable with Gradle plugin 2.0-beta3 – piotrek1543 Jan 12 '16 at 17:19
  • @manitaz, try to build your project in Android Studio, please - if it would work, then try by terminal and compare - I mean check if both would work fine. Don't invalidate? ok, so clean and buld again – piotrek1543 Jan 12 '16 at 17:20
40

Current work around is to overrideVersionCheck: In your build.gradle

buildscript {

System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
     ...
}

Check this link for more Details

Testing Singh
  • 1,347
  • 1
  • 15
  • 26
23

Just Change in build.gradle file

 classpath 'com.android.tools.build:gradle:1.3.0'

To

 classpath 'com.android.tools.build:gradle:2.0.0'
  1. Now GoTo -> menu choose File -> Invalidate Caches/Restart...

  2. Choose first option: Invalidate and Restart

    Android Studio would restart.

    After this, it should work normally.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Jitendra Singh
  • 399
  • 4
  • 14
  • The android studio and gradle version as very messy. In my case, I have to set the version to current latest: classpath 'com.android.tools.build:gradle:2.1.3'. My android studio version is: Android studio 2.2RC – Jianwu Chen Sep 05 '16 at 22:07
15

Based on https://developer.android.com/studio/releases/gradle-plugin.html ...

The following table lists which version of Gradle is required for each version of the Android plugin for Gradle. For the best performance, you should use the latest possible version of both Gradle and the Android plugin.

So, the Plugin version with Required Gradle version should be match.

enter image description here

Bill
  • 1,268
  • 14
  • 14
2

Here's what I did to fix this:

1) Create a new project

2) open the gradle-wrapper.properties file and copy the distributionUrl to your project e.g.:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip

3) open the build.gradle (Project) and copy the gradle dependency to your project e.g.:

classpath 'com.android.tools.build:gradle:2.3.0-beta1'

4) File --> Invalidate Caches / Restart (I think a re-sync may have sufficed, but didn't try it)

5) Delete that project you made (optional)

Look, this is a silly way to do things, but Android Studio is free so who am I to complain...

Moe Singh
  • 809
  • 7
  • 12
  • This worked with IntelliJ IDEA 2019.2, except that an additional line `google()` had to be copied from the fake project's `build.gradle` file. – RenniePet Aug 11 '19 at 03:57
1

Use ./gradlew instead of gradle to resolve this issue.

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
shekar
  • 1,251
  • 4
  • 22
  • 31
0

The android studio and Gradle version looks like very bad managed. And there's tons of version in-capability issues. And the error message is mostly clueless. For this particular issue. The closest answer is from "Jitendra Singh". Change the version to:

 classpath 'com.android.tools.build:gradle:2.0.0'

But in my case: Android studio 2.2 RC, I still get another error:

Could not find matching constructor for: com.android.build.gradle.internal.LibraryTaskManager(org.gradle.api.internal.project.DefaultProject_Decorated, com.android.builder.core.AndroidBuilder, android.databinding.tool.DataBindingBuilder, com.android.build.gradle.LibraryExtension_Decorated, com.android.build.gradle.internal.SdkHandler, com.android.build.gradle.internal.DependencyManager, org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry)

So I went to the maven central to find the latest com.android.tools.build:gradle version which is 2.1.3 for now. So after change to

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}

Solved my problem eventually.

Jianwu Chen
  • 5,336
  • 3
  • 30
  • 35
0

I Had similar issue. Every project has his own gradle folder, check if in your project root there's another gradle folder:

/my_projects_root_folder/project/gradle
/my_projects_root_folder/gradle

If so, in every folder you'll find /gradle/wrapper/gradle-wrapper.properties.

Check if in /my_projects_root_folder/gradle/gradle-wrapper.properties gradle version at least match /my_projects_root_folder/ project/ gradle/ gradle-wrapper.properties gradle version

Or just delete/rename your /my_projects_root_folder/gradle and restart android studio and let Gradle sync work and download required gradle.

ldt
  • 1
  • 1