Learn how to solve the Gradle exception when implementation is not recognized.

How to solve Android error: Could not find method implementation() for arguments on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

The implementation instruction is a dependency configuration that is used for library declaration. It was introduced in Gradle 3. So this exception is triggered always when Gradle doesn't recognize the implementation instruction.

In this article I will explain to you possible solutions to this problem in Android Studio.

Possible solution #1 (wrong build.gradle)

It's very likely that you are trying to add a dependency in the project build.gradle file. As you may know, you shouldn't include the dependencies in the Project gradle as you are supposed to add the dependencies on the individual module build.gradle:

Gradle Build Project

So if you add the dependencies in the project gradle like this:

// Project/build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        implementation "androidx.activity:activity:1.3.1"
        implementation "androidx.fragment:fragment:1.3.6"
    }
}

The exception will be thrown if you try to synchronize your project. Be sure to add the dependencies in the individual gradle files:

// Project/app/build.gradle
dependencies {
    implementation "androidx.activity:activity:1.3.1"
    implementation "androidx.fragment:fragment:1.3.6"
}

Possible solution #2 (outdated Gradle)

When using the implementation instruction in the configuration of a Gradle plugin whose version is less than 3.0, implementation won't be recognized and therefore the exception will be thrown. If that's the case, replace implementation to compile, testImplementation to testCompile and androidTestImplementation to androidTestCompile:

// Project/app/build.gradle
dependencies {
    compile "androidx.activity:activity:1.3.1"
    compile "androidx.fragment:fragment:1.3.6"
}

Possible solution #3 (upgrade Gradle)

If downgrading the instructions from implementation to compile isn't an option, you may upgrade Gradle to the latest version. To do this, navigate to your project tree and look into app, then Gradle Scripts and locate the build.gradle file (Project: app). In this Gradle build filupdate the classpath to the latest version of the Gradle build plugin:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

After updating the classpath, navigate to your App, then Gradle Scripts and select the gradle-wrapper.properties file and update the distributionUrl to the latest version of Gradle:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

After this change you will need to synchronize your project and you should be able to include dependencies using the implementation instruction.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors