Java 无法在对象上找到参数 [directory 'libs'] 的方法 implementation()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51136966/
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
Could not find method implementation() for arguments [directory 'libs'] on object
提问by Gears2Apps
Error Message:- Could not find method implementation() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Code
错误消息:- 无法在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象上找到参数 [directory 'libs'] 的方法 implementation()。
代码
apply plugin: 'com.android.application'
ext {
supportVersion='27.1.1'
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.eassycars.www.dlservices"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildscript {
repositories {
jcenter()
}
configure(':app') {
dependencies {
classpath 'com.android.tools.build.gradle:4.8.1'
implementation fileTree (include: ['*.jar'], dir: 'libs')
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler :$supportVersion"
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:cardview-v7:$supportVersion"
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.android.support:palette-v7:$supportVersion"
implementation "com.android.support:customtabs:$supportVersion"
implementation "com.android.support:support-v4:$supportVersion"
implementation 'com.google.android.exoplayer:exoplayer:r2.0.4'
// utils
implementation 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
implementation 'com.koushikdutta.ion:ion:2.1.7'
implementation 'com.github.Commit451:bypasses:1.0.4'
implementation 'com.jakewharton:butterknife:8.8.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.0'
implementation 'com.drewnoakes:metadata-extractor:2.9.1'
implementation 'com.orhanobut:hawk:2.0.1'
classpath 'com.google.gms:google-services:3.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
}}
}
}
回答by Udit
Remove the space between version:
删除版本之间的空格:
implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler:$supportVersion"
Also, please move the dependencies block out of the android block:
另外,请将依赖项块移出 android 块:
android {
...
}
...
dependencies{
...
}
回答by ??? ???? ????
Because you have incorrect block in your build.gradle. Looks like you're mixing top levelbuild.gradle and module build.gradle. Your appmodule build.gradle should be something like this:
因为你的 build.gradle 中有不正确的块。看起来您正在混合顶级build.gradle 和模块 build.gradle。你的应用模块 build.gradle 应该是这样的:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
...
}
buildTypes {
release {
...
}
}
..
}
dependencies {
...
}
please visit Configure your buildfor details.
有关详细信息,请访问配置您的构建。
回答by philburk
I updated the "distributionUrl in my "gradle/wrapper/gradle-wrapper.properties" file to match the current gradle version.
我更新了“gradle/wrapper/gradle-wrapper.properties”文件中的“distributionUrl”以匹配当前的gradle版本。
I also updated the classpath in my top level build.gradle file to match the gradle API level.
我还更新了顶级 build.gradle 文件中的类路径以匹配 gradle API 级别。
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
Re-synced and then it built OK.
重新同步,然后就可以了。