Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]

JavaAndroidAndroid StudioAndroid Gradle-Plugin

Java Problem Overview


I am trying to open existing android project in android studio and it gradle cannot build the app without the error

Error android studio keeps on throwing

Error:(74, 1) A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments 
[com.android.support:appcompat-v7:26.0.0] on object of type 
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

My Code in build.gradle Which can help to understand my issue My dependencies

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')

// google & support
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"

}

Please help to solve the issue

Java Solutions


Solution 1 - Java

Make sure you're adding these dependencies in android/app/build.gradle, not android/build.gradle

Solution 2 - Java

Replace compile with implementation.

compile was recently deprecated and replaced by implementation or api

Solution 3 - Java

Make sure your Gradle version is 3.*.* or higher before using "implementation".

Open the project level Gradle file under dependencies:

dependencies{
    classpath 'com.android.tools.build:gradle:3.1.2'
}

Open the 'gradle-wrapper.properties' file and set the distributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

or latest version.

Sync the project. I Hope this solves your problem.

Solution 4 - Java

You need to use at least Gradle 3.4 or newer to be able to use implementation. It is not recommended to keep using the deprecated compile since this can result in slower build times. For more details see the official android developer guide:

> When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime. Using this dependency configuration instead of api or compile can result in significant build time improvements because it reduces the amount of projects that the build system needs to recompile. For example, if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations

Update: compile will be removed by end of 2018, so make sure that you use only implementation now:

> Warning:Configuration 'compile' is obsolete and has been replaced with > 'implementation'. It will be removed at the end of 2018

Solution 5 - Java

change apply plugin: 'java' to apply plugin: 'java-library'

java-library-plugin

Solution 6 - Java

For me I put my dependencies in the wrong spot.

buildscript {
  dependencies {
    //Don't put dependencies here.
  }
}

dependencies {
 //Put them here
}

Solution 7 - Java

So ridiculous, but I still wanna share my experience in case of that someone falls into the situation like me.

Please check if you changed: compileSdkVersion --> implementationSdkVersion by mistake

Solution 8 - Java

I moved implementation to module-level build.gradle from root-level build.gradle. It solves the issue.

Solution 9 - Java

Your Code

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

Replace it By

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')

Solution 10 - Java

Replace your implementation with classpath. That should work.

Solution 11 - Java

Solved this by adding my dependancies in the app folder

Go to app < Gradle Scripts < gradle.build(Module: app) and add the depandancies in that file and not the global build.gradle file

enter image description here

Solution 12 - Java

As mentioned here, https://stackoverflow.com/a/50941562/2186220, use gradle plugin version 3 or higher while using 'implementation'.

Also, use the google() repository in buildscript.

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

These changes should solve the issue.

Solution 13 - Java

As suggested in official docs you need add these :

buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android Gradle plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
    }
}

adding these remove my error. Also use implementation instead of compile.

Solution 14 - Java

In my case it was because I used Implementation instead of implementation.

Solution 15 - Java

If implementation is not defined, you are writing on a wrong file. On Unity 2019+ the correct file is main template grandle and not some of the others.

Solution 16 - Java

For me the problem was, i wrote :

android { compileSdk 31 .....

instead of:

android { compileSdkVersion 31

So make sure build.gradle is correct.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncoleView Question on Stackoverflow
Solution 1 - JavaSunil KumarView Answer on Stackoverflow
Solution 2 - JavaSaurabh ThoratView Answer on Stackoverflow
Solution 3 - JavakrishnamurthyView Answer on Stackoverflow
Solution 4 - JavadonfuxxView Answer on Stackoverflow
Solution 5 - Javaxiqing lauView Answer on Stackoverflow
Solution 6 - JavaFriedrickView Answer on Stackoverflow
Solution 7 - JavaNguyen Tan DatView Answer on Stackoverflow
Solution 8 - Javauser8783065View Answer on Stackoverflow
Solution 9 - JavaSaurabh kumarView Answer on Stackoverflow
Solution 10 - JavaEdward MpanzaView Answer on Stackoverflow
Solution 11 - JavaDereckChambokoView Answer on Stackoverflow
Solution 12 - JavaBotView Answer on Stackoverflow
Solution 13 - JavaAli Yar KhanView Answer on Stackoverflow
Solution 14 - JavaBouhView Answer on Stackoverflow
Solution 15 - JavaGeorge TView Answer on Stackoverflow
Solution 16 - JavaRamasieView Answer on Stackoverflow