Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle sync failed: Unable to find method

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.+' } 
like image 282
Kal747 Avatar asked Jun 06 '16 11:06

Kal747


2 Answers

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.

like image 162
Shangwu Avatar answered Sep 22 '22 05:09

Shangwu


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)

like image 34
KunMing Xie Avatar answered Sep 22 '22 05:09

KunMing Xie