在对象上找不到参数[目录'libs']的方法Implementation()

时间:2018-07-02 13:06:57

标签: java android build.gradle

  

错误消息:-找不到参数[目录的方法Implementation()   'libs']类型的对象   org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。

     

代码

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'
        }}
    }
}

3 个答案:

答案 0 :(得分:0)

删除版本之间的空格:

implementation "com.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler:$supportVersion"

另外,请将依赖项块移出android块:

android {
...
}
...
dependencies{
...
}

答案 1 :(得分:0)

因为在build.gradle中有不正确的块。看起来您正在混合顶级 build.gradle和模块build.gradle。您的 app 模块build.gradle应该是这样的:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.3'

  defaultConfig {
    ...
  }
  buildTypes {
    release {
      ...
    }
  }

  ..
}

dependencies {
  ...
}

请访问Configure your build了解详情。

答案 2 :(得分:0)

我更新了“ gradle / wrapper / gradle-wrapper.properties”文件中的“ distributionUrl”,以匹配当前的gradle版本。

我还更新了顶层build.gradle文件中的类路径以匹配gradle API级别。

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

重新同步,然后构建成功。