[英]Gradle error Android Studio
I'm trying to build a project but it keeps giving me this gradle error I have upgraded my gradle 3.3 and my android plugin version to 2.3.3 but it's still giving me error Any help would be appreciated Error: 我正在尝试构建一个项目,但它一直给我这个gradle错误我已经将我的gradle 3.3和我的android插件版本升级到2.3.3但它仍然给我错误任何帮助将被赞赏错误:
Error:(40, 0) Gradle DSL method not found: 'implementation()' Possible causes: 错误:(40,0)未找到Gradle DSL方法:'implementation()'可能的原因:
Event Log: Gradle sync failed: Could not find method implementation() for arguments [com.android.support.constraint:constraint-layout:1.0.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 事件日志:Gradle同步失败:无法在类型为org.gradle.api.internal.artifacts.dsl.dependencies的对象上找到参数[com.android.support.constraint:constraint-layout:1.0.2]的方法实现() .DefaultDependencyHandler。
build.gradle file: build.gradle文件:
buildscript {
ext.kotlin_version = '1.1.2-5'
ext.support_lib_version = '25.3.1'
ext.junit_version = '4.12'
ext.constraint_layout_version = '1.0.2'
ext.rxjava_version = '1.1.3'
ext.rxandroid_version = '1.1.0'
ext.mpchart_version='v3.0.2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties file: gradle-wrapper.properties文件:
#Mon Jun 19 10:49:52 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
try this gradle configuration ,it works for me : 试试这个gradle配置,它对我有用:
buildscript {
ext.kotlin_version = '1.1.2-5'
ext.support_lib_version = '25.3.1'
ext.junit_version = '4.12'
ext.constraint_layout_version = '1.0.2'
ext.rxjava_version = '1.1.3'
ext.rxandroid_version = '1.1.0'
ext.mpchart_version = 'v3.0.2'
ext.realm_version = '3.3.2'
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:$realm_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} }
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
maven { url "https://jitpack.io" }
}
} }
task clean(type: Delete) {
delete rootProject.buildDir
} }
add maven { url 'https://maven.google.com' }
in repositories
在repositories
添加maven { url 'https://maven.google.com' }
And use Android studio 3.0 preview for this configuration. 并使用Android studio 3.0预览进行此配置。
simply add this into your project level gradle 只需将其添加到项目级别gradle中
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
it is because you have implementation() method in your app level gradle file 这是因为你的app level gradle文件中有implementation()方法
This is an answer tested and works on Android Studio 3.0 Canary 6. 这是一个经过测试的答案,适用于Android Studio 3.0 Canary 6。
Upgrade gradle version in your project level gradle classpath to a more recent one. 将项目级gradle类路径中的gradle版本升级到更新版本。
Of what I understand regarding the official documentation about gradle / gradle plugin version compatibility it should work with gradle plugin version 2.3.3 and gradle version 3.3 (anybody correct me if I'm wrong): 关于gradle / gradle插件版本兼容性的官方文档我理解的是它应该与gradle插件版本2.3.3和gradle版本3.3一起使用(如果我错了,任何人都会纠正我):
Anyway I had to upgrade the plugin to version 3.0.0-alpha6 to get rid of the error. 无论如何,我不得不将插件升级到版本3.0.0-alpha6以摆脱错误。 To do so make this change in project level build.gradle : 为此,请在项目级build.gradle中进行此更改:
dependencies {
...
classpath 'com.android.tools.build:gradle:3.0.0-alpha6'
Note I had a different gradle version than yours in my gradle-wrapper.properties (4.1): 注意我的gradle-wrapper.properties(4.1)中有一个与你不同的gradle版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-milestone-1-all.zip
So if you change these both lines in these both files it should works. 因此,如果您在这两个文件中更改这两行,它应该可以工作。 Note that com.android.tools.build:gradle:3.0.0-alpha4
suggested by @Narendra kumawat didn't work for me, I had to use alpha6. 请注意,@ Narendra kumawat建议的com.android.tools.build:gradle:3.0.0-alpha4
对我不起作用,我不得不使用alpha6。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.