【问题标题】:Gradle sync failed: Unable to find methodGradle 同步失败:找不到方法
【发布时间】:2016-10-05 23:10:59
【问题描述】:

我尝试在 Android Studio 中导入一个项目。导入时,Gradle 出现错误:

Gradle sync failed: Unable to find method 

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

我试过了:

  • 重新下载依赖和同步项目:失败(同样的错误)。

  • 停止 Gradle 构建过程:失败(同样的错误)。

  • 删除主目录中的 .graddle:失败(同样的错误)。

  • 使缓存无效并重新启动失败(同样的错误)。

  • 卸载并重新安装 Android Studio 和 SDK:失败(同样的错误)。

/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.+'
}

【问题讨论】:

  • 要排除的几件事,尝试清除构建文件夹并在任务管理器中停止 java,这通常可以解决我遇到的大多数 gradle 问题
  • 更专注地构建日志。就我而言,我已经过时了 AppCenter gradle 插件

标签: java android android-studio gradle


【解决方案1】:

我通过更改以下内容修复了错误。

  1. 打开 your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties 下的文件
  2. 用这个替换旧的 URL 路径: distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip

  3. 将文件夹名称从“...\1.12”重命名为 your-app-project\your-app-name.gradle\2.10

  4. 将 your-app-project\your-app-name\build.gradle 的类路径更改为 类路径'com.android.tools.build:gradle:2.1.2'

  5. 将 your-app-project\your-app-name\app\build.gradle 的 runProguard 替换为 minifyEnabled

  6. 点击错误提示上的重试或重新打开您的 Android Studio 和项目。

我正在使用最新版本的 Android Studio 和 Gradle。

【讨论】:

  • 2 号解决了我的问题。我遇到的问题是我在 Android Studio 2.2.2 中打开了一个项目,该项目是在 1.0.0 版的 android studio 版本中创建的
  • 2) 也为我工作。在我的例子中,我将这一行替换为:distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
  • 我的 gradle-wrapper.properties 文件中已经有 distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip,但仍然有同样的错误。
  • 令人惊讶的是,新版本比旧版本存在更多问题。日食万岁...
  • 即使我的版本为distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip,我也会遇到同样的错误。如何解决这个问题?
【解决方案2】:

编辑项目 >> 应用 >> gradle >> 包装器 >> gradle-wrapper.properties

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

重建项目(重新启动你的想法)

【讨论】:

  • 让我开心。 Tks
【解决方案3】:

我今天在 Windows 7 64 位上使用 Android Studio 2.2 Beta2 时遇到了这个问题。

提到的解决方案都没有帮助。最后我能够通过重新导入我的项目来解决这个问题。

【讨论】:

    【解决方案4】:
    Project >> App >> gradle >> wrapper >> gradle-wrapper.properties
    
    https\://services.gradle.org/distributions/gradle-4.1-all.zip
    

    这肯定会奏效。我遇到了同样的问题。这样就解决了。

    【讨论】:

      【解决方案5】:

      对我来说,解决方案是打开 Settings -> Build, Execution, Deployment -> Gradle 并选中“Use default gradle wrapper (recommended)”。

      【讨论】:

        【解决方案6】:

        我能够将 /.gradle 文件夹从一个新的 Android 项目复制到有问题的项目中。然后我重新启动了 Android Studio 并进行了清理/构建。这解决了我的问题。

        【讨论】:

          【解决方案7】:

          我遇到了类似的问题,我通过以下方式解决了它 Android Studio 版本 3.0.1

          1.将your-app-project\your-app-name\build.gradle的classpath改为classpath 'com.android.tools.build:gradle:3.0.1'。

          2.用这个替换旧的URL路径:distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip

          我的 gradle 文件是 4.1 版 即;文件位于以下位置:(您的机器可能略有不同) C:\Program Files\Android\Android Studio\gradle\gradle-4.1

          【讨论】:

            【解决方案8】:

            在gradle->gradle-wrapper.properties下

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

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

            解决了这个问题。

            【讨论】:

              【解决方案9】:

              当我将我的 android studio 更新到 3.1.1 时出现此问题

              1。 我已经通过更改解决了它: classpath 'com.android.tools.build:gradle:3.1.1' 在 build.gradle(项目)中

              2。 改变: distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 在 gradle-wrapper.properties 中。 (可以在资源管理器 C:\Program Files\Android\Android Studio\gradle\gradle-4.4 中查看)

              【讨论】:

                【解决方案10】:
                    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
                

                第 4 步:最后 goto build>rebuild project...

                ......结束@Ambilpura

                【讨论】:

                  【解决方案11】:

                  答案是部分多余的,但它适用于那些对添加什么版本的 gradle 发行版感到困惑的人。 这是安装在您机器上的 gradle 版本。

                  例如: 通过以下方式检查您的 gradle 版本: “gradle -v”(我的是 5.4.1)

                  更新文件“your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties” distributionUrl=https://services.gradle.org/distributions/gradle-5.4.1-all.zip

                  完成了!它为我解决了这个问题。

                  【讨论】:

                    猜你喜欢
                    • 2019-04-02
                    • 1970-01-01
                    • 2019-07-26
                    • 1970-01-01
                    • 1970-01-01
                    • 2020-09-16
                    • 1970-01-01
                    • 2023-03-25
                    • 1970-01-01
                    相关资源
                    最近更新 更多