无法为参数[目录'libs']找到方法api()

时间:2018-03-22 07:58:24

标签: android android-studio android-gradle-3.0

打开文件

这是我的gradle文件:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.1"
        defaultConfig {
            applicationId "com.landdrops.cricketfantacy.androidbottom"
            minSdkVersion 21
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation 'com.android.support:appcompat-v7:27.0.1'
        implementation 'com.android.support:design:27.0.1'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test.runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    }

我正在

  

错误:(23,0)无法在类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象上找到参数[directory'libs']的方法实现()。   打开文件

2 个答案:

答案 0 :(得分:18)

对于我的Java库项目,我需要使用java-library插件而不是java

- apply plugin: 'java'
+ apply plugin: 'java-library'

答案 1 :(得分:1)

我能够通过将大多数依赖项更新到当前版本来更正此错误(不确定是否必要,并且当最新版本与另一个组件的依赖项冲突时,我还原了一个版本并清除了不匹配。这次,我使用27.1.0进行appCompat,设计。(我使用27.0.3进行构建工具)

Gradle包装到版本4.4(这实际上是在加载过时的项目和更新插件时提示我做的)

调整后的项目build.gradle使用: classpath' com.android.tools.build:gradle:3.1.1'