50

I try to import a project in Android studio. When importing it, i've got an Error with Gradle :

Gradle sync failed: Unable to find method 

'org.gradle.api.artifacts.Configuration.setExtendsFrom(Ljava/lang/Iterable;)Lorg/gradle/api/artifacts/Configuration;'.

I have tried :

  • Re-download dependencies and sync project: Fail (same error).

  • Stop Gradle build processes: Fail (same error).

  • Delete the .graddle in the home directory: Fail (same error).

  • Invalidate cache and restart Fail (same error).

  • Uninstall and reinstall Android studio and SDK: Fail (same error).

/build.gradle :

// 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.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

/app/build.gradle

apply plugin: 'com.android.application'
//apply plugin: 'android'

android {
    compileSdkVersion 17
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'xxx.xxx.xxx'
        minSdkVersion 17
        targetSdkVersion 17
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        buildPB {
            debuggable false
            jniDebuggable false
            renderscriptDebuggable false

            zipAlignEnabled true
        }
    }
    productFlavors {
    }
//    lintOptions {
//        abortOnError false
//    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile ('org.simpleframework:simple-xml:2.7.1') {
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }
    compile 'net.sf.opencsv:opencsv:2.3'
    compile 'de.greenrobot:greendao:1.3.7'
    // You must install or update the Support Repository through the SDK manager to use this dependency.
//    compile 'com.android.support:support-v4:19.+'
}
roottraveller
  • 7,942
  • 7
  • 60
  • 65
Kal747
  • 619
  • 1
  • 5
  • 10
  • Couple of things to to rule out, try clearing your build folder and stopping java in task manager, this normally fixes most gradle issues I have – dave Jun 06 '16 at 11:11
  • Look to Build logs more attentively. In my case, I has outdated AppCenter gradle plugin – Deni Erdyneev Feb 25 '20 at 05:50

11 Answers11

98

I fixed the error by changing the following things.

  1. Open the file under your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties

  2. replace the old URL path by this one: distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

  3. Rename the folder name from "...\1.12" to your-app-project\your-app-name\.gradle\2.10

  4. Change the classpath of your-app-project\your-app-name\build.gradle to classpath 'com.android.tools.build:gradle:2.1.2'

  5. Replace runProguard of your-app-project\your-app-name\app\build.gradle by minifyEnabled

  6. Click Retry on the error reminder or Reopen your Android Studio and project.

I am using the latest versions of Android Studio and Gradle.

Boken
  • 4,825
  • 10
  • 32
  • 42
Shangwu
  • 1,440
  • 12
  • 12
  • 16
    Number 2 solved my problem. The problem I had was I was opening a project in Android Studio 2.2.2 that was created in a version of android studio in version 1.0.0 – ant2009 Nov 11 '16 at 18:36
  • 1
    2) worked for me too. In my case, I replaced the line with: distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip – Kenneth Browning Feb 02 '18 at 10:48
  • 10
    I already have `distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip` in my gradle-wrapper.properties file, but still having the same error. – Narendra Singh Feb 06 '18 at 08:21
  • It's amazing how new versions have way more problem than older ones. Long live eclipse... – Pedro Lobito Aug 14 '19 at 13:04
  • I am getting the same error even though I have version `distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip`. how to solve this? – roottraveller Sep 13 '19 at 12:25
15

edit Project >> App >> gradle >> wrapper >> gradle-wrapper.properties

distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-bin.zip

rebuild the project (restart ide in your mind)

KunMing Xie
  • 1,613
  • 17
  • 15
6
Project >> App >> gradle >> wrapper >> gradle-wrapper.properties

https\://services.gradle.org/distributions/gradle-4.1-all.zip

This will surely work. I was having same issue. Solved by this.

Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
Raja Muddasar
  • 101
  • 1
  • 2
5

This issue appears when I updated my android studio to 3.1.1

1. I have resolved it by changing: classpath 'com.android.tools.build:gradle:3.1.1' in build.gradle (project)

2. change: distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip in gradle-wrapper.properties. (you can check it in explorer C:\Program Files\Android\Android Studio\gradle\gradle-4.4)

syed shah
  • 91
  • 2
  • 3
4

I faced similar issue and i resolved it by Android Studio Version 3.0.1

1.Change the classpath of your-app-project\your-app-name\build.gradle to classpath 'com.android.tools.build:gradle:3.0.1'.

2.Replace the old URL path by this one: distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

My gradle file was of version 4.1 ie; file in following location:(may differ slightly in your machine) C:\Program Files\Android\Android Studio\gradle\gradle-4.1

Boken
  • 4,825
  • 10
  • 32
  • 42
Kokul Jose
  • 1,384
  • 2
  • 14
  • 26
2

Under gradle->gradle-wrapper.properties

replacing

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

with

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

solved the issue.

Boken
  • 4,825
  • 10
  • 32
  • 42
Daniel
  • 51
  • 4
1

This issue happened to me today with Android Studio 2.2 Beta2 on Windows 7 64-bit.

None of the solutions mentioned helped. Finally I was able to resolve the issue by re-importing my project.

0

For me the solution was to open Settings -> Build, Execution, Deployment -> Gradle and check "Use default gradle wrapper (recommended)".

gingo
  • 3,149
  • 1
  • 23
  • 32
0

I was able to copy over the /.gradle folder from a new Android project into the one that was having the problem. Then I restarted Android Studio and did a clean/build. This resolved my issue.

0
    After 1 hour R&D Not Solution as worked for me...

    But still i have solution follow this its work 100

    step 1: upgrade your build.gradle(Project:<your project name>)
    Example :  classpath 'com.android.tools.build:gradle:2.1.3' // old gradle file
               classpath 'com.android.tools.build:gradle:2.3.1' // upgraded file 

                                OR
               classpath 'com.android.tools.build:gradle:3.1.0'

    Step 2 : Upgrade compileSdkVersion buildToolsVersion 
    Example : compileSdkVersion 23    buildToolsVersion "23.0.3 // old api's
              compileSdkVersion 25    buildToolsVersion "25.0.2" // upgraded api's

   Step 3:  upgrade gradle-wrapper.properties 

Example : distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip // old or any version

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip // new or any version

Step 4 : finally goto build>rebuild project...

......End @Ambilpura

0

The answer is partially reduntant, but it's for those who are confused with what version of gradle distribution to add. It's the gradle version that's installed on your machine.

Ex: Check your gradle version by: "gradle -v" (mine was 5.4.1)

Update the file "your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties" with distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip

And done! It solved the problem for me.

Amrit Kr Lama
  • 109
  • 2
  • 11