Java Gradle 同步失败:无法找到方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37655814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle sync failed: Unable to find method
提问by Kal747
I try to import a project in Android studio. When importing it, i've got an Error with Gradle :
我尝试在 Android Studio 中导入一个项目。导入时,我遇到了 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).
重新下载依赖项并同步项目:失败(同样的错误)。
停止 Gradle 构建过程:失败(相同错误)。
删除主目录中的 .graddle:失败(同样的错误)。
使缓存无效并重新启动失败(相同的错误)。
卸载并重新安装 Android Studio 和 SDK:失败(同样的错误)。
/build.gradle :
/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
/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.+'
}
采纳答案by Shangwu
I fixed the error by changing the following things.
我通过更改以下内容修复了错误。
- Open the file under your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties
replace the old URL path by this one: distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
Rename the folder name from "...\1.12" to your-app-project\your-app-name.gradle\2.10
Change the classpath of your-app-project\your-app-name\build.gradle to classpath 'com.android.tools.build:gradle:2.1.2'
Replace runProguard of your-app-project\your-app-name\app\build.gradle by minifyEnabled
Click Retry on the error reminder or Reopen your Android Studio and project.
- 打开 your-app-project\your-app-name\gradle\wrapper\gradle-wrapper.properties 下的文件
用这个替换旧的 URL 路径:distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
将文件夹名称从“...\1.12”重命名为 your-app-project\your-app-name.gradle\2.10
将 your-app-project\your-app-name\build.gradle 的类路径更改为类路径 'com.android.tools.build:gradle:2.1.2'
用 minifyEnabled 替换 your-app-project\your-app-name\app\build.gradle 的 runProguard
单击错误提示上的重试或重新打开您的 Android Studio 和项目。
I am using the latest versions of Android Studio and Gradle.
我正在使用最新版本的 Android Studio 和 Gradle。
回答by KunMing Xie
edit Project >> App >> gradle >> wrapper >> gradle-wrapper.properties
编辑项目 >> 应用程序 >> gradle >> 包装器 >> gradle-wrapper.properties
distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-bin.zip
rebuild the project (restart ide in your mind)
重建项目(在你的脑海中重启ide)
回答by Thomas Sunderland
This issue happened to me today with Android Studio 2.2 Beta2 on Windows 7 64-bit.
我今天在 Windows 7 64 位上使用 Android Studio 2.2 Beta2 发生了这个问题。
None of the solutions mentioned helped. Finally I was able to resolve the issue by re-importing my project.
提到的解决方案都没有帮助。最后,我能够通过重新导入我的项目来解决该问题。
回答by Raja Muddasar
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.
这肯定会奏效。我有同样的问题。以此解决。
回答by gingo
For me the solution was to open Settings -> Build, Execution, Deployment -> Gradle and check "Use default gradle wrapper (recommended)".
对我来说,解决方案是打开设置 -> 构建、执行、部署 -> Gradle 并选中“使用默认 gradle 包装器(推荐)”。
回答by Travis Gibson
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.
我能够将 /.gradle 文件夹从一个新的 Android 项目复制到有问题的项目中。然后我重新启动了 Android Studio 并进行了清理/构建。这解决了我的问题。
回答by Kokul Jose
I faced similar issue and i resolved it by Android Studio Version 3.0.1
我遇到了类似的问题,我通过 Android Studio 版本 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'.
1.将your-app-project\your-app-name\build.gradle的classpath改为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
2.用这个替换旧的URL路径: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
我的 gradle 文件是 4.1 版,即以下位置的文件:(可能与您的机器略有不同)C:\Program Files\Android\Android Studio\gradle\gradle-4.1
回答by Daniel
Under gradle->gradle-wrapper.properties
在 gradle->gradle-wrapper.properties 下
replacing distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
替换 distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
with
和
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
solved the issue.
解决了这个问题。
回答by syed shah
This issue appears when I updated my android studio to 3.1.1
当我将我的 android studio 更新到 3.1.1 时出现这个问题
1.
I have resolved it by changing:
classpath 'com.android.tools.build:gradle:3.1.1'
in build.gradle (project)
1.我已经通过更改解决了:
classpath 'com.android.tools.build:gradle:3.1.1'
在build.gradle(项目)中
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)
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 中查看)
回答by Ambilpura Sunil Kumar
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...
第 4 步:最后转到 build>rebuild project...
......End @Ambilpura
......结束@Ambilpura