Could not find method api() for arguments [directory 'libs']
Asked Answered
V

2

30

Open File

This is my gradle file:

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

I am getting

Error:(23, 0) Could not find method implementation() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Open File

Virginity answered 22/3, 2018 at 7:58 Comment(3)
What is your gradle version and android plugin version?Catheterize
try replacing compile with implementation.Shennashensi
I have tried using implementation and API But non worked.Virginity
K
1

I was able to correct this error by updating most dependencies to current version (not sure that necessary, and when the most current version conflicted with a dependency of another component, I reverted one release back and it cleared up the mismatch. At this time, I am using 27.1.0 for appCompat, design. (I use 27.0.3 for build tools tho)

Gradle wrapper to version 4.4 (this was actually prompted for me to do when loading an outdated project and updating the plugin)

Adjusted project build.gradle to use: classpath 'com.android.tools.build:gradle:3.1.1'

Katherinkatherina answered 18/4, 2018 at 18:53 Comment(0)
C
89

For my Java library project I needed to use java-library plugin instead of java:

- apply plugin: 'java'
+ apply plugin: 'java-library'
Condign answered 13/1, 2020 at 4:22 Comment(0)
K
1

I was able to correct this error by updating most dependencies to current version (not sure that necessary, and when the most current version conflicted with a dependency of another component, I reverted one release back and it cleared up the mismatch. At this time, I am using 27.1.0 for appCompat, design. (I use 27.0.3 for build tools tho)

Gradle wrapper to version 4.4 (this was actually prompted for me to do when loading an outdated project and updating the plugin)

Adjusted project build.gradle to use: classpath 'com.android.tools.build:gradle:3.1.1'

Katherinkatherina answered 18/4, 2018 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.