Gradle同步失败:无法找到方法 [英] Gradle sync failed: Unable to find method
问题描述
我试图在Android studio中导入一个项目。
导入它时,我得到了一个Gradle错误:
Gradle同步失败:无法找到方法'org.gradle.api.artifacts.Configuration.setExtendsFrom(Ljava / lang / Iterable;)Lorg / gradle / api / artifacts / Configuration;'。
我尝试过:
- 重新下载依赖项并同步项目:失败(同样的错误)。
- $
-
删除home目录中的.graddle:失败(相同的错误)。/ b>
-
使缓存失效并重新启动:失败(同样的错误)。
卸载并重新安装Android Studio和SDK:失败(同样的错误)。
我还没有想法
/build.gradle:
//顶层构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
$ b buildscript {
repositories {
jcenter()
}
依赖关系{
classpath'com.android.tools.build:gradle: 2.1.0'
//注意:不要在这里放置您的应用程序依赖关系;它们属于单个模块build.gradle文件中的
//
}
}
allprojects {
存储库{
jcenter()
$ / code $ / pre
$ b $ /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
//}
}
依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
//您必须安装或更新Support Repository SDK管理器使用此依赖关系。
compile('org.simpleframework:simple-xml:2.7.1'){
排除模块:'stax'
排除模块:'stax-api'
排除模块: 'xpp3'
}
编译'net.sf.opencsv:opencsv:2.3'
编译'de.greenrobot:greendao:1.3.7'
//您必须安装或通过SDK管理器更新支持存储库以使用此依赖关系。
// compile'com.android.support:support-v4:19.+'
}
在此先感谢
解决方案我通过更改以下内容修复了错误。
$ b
- 在您的应用程序项目下打开文件您的应用程序名称\gradle\wrapper\gradle-wrapper.properties
-
替换旧的URL路径:
distributionUrl = https://services.gradle.org/distributions/gradle-2.10-all.zip
-
将文件夹名称从... \1.12重命名为您的应用程序项目\您的应用程序名称.gradle \2.10
-
将您的应用程序项目的类路径更改为
classpath com.android.tools.build:gradle:2.1。 2'
-
用minifyEnabled替换your-app-project \ your-app-name\app\build.gradle的runProguard
-
在错误提醒上点击重试或重新打开您的Android Studio并重新打开
我使用最新版本的Android Studio和Gradle。
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 tryed to :
- Re-download dependencies and sync project : Fail (same error).
Stop Gradle build processess : Fail (same error).
Delete the .graddle in home directory : Fail (same error).
Invalidate cache and restart : Fail (same error).
Uninstall and reinstall Android studio and SDK : Fail (same error).
I have no yet ideas
/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.+'
}
Thanks in advance
解决方案 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.
I am using the latest versions of Android Studio and Gradle.
这篇关于Gradle同步失败:无法找到方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!