38

I had this error

Error:(45, 0) Gradle DSL method not found: 'implementation()'
Possible causes:<ul><li>The project 'LaTaxi2' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
<a href="fixGradleElements">Upgrade plugin to version 2.3.3 and sync project</a></li><li>The project 'LaTaxi2' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

build.gradle content

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
//        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        /* CHANGE to classpath 'com.android.tools.build:gradle:2.3.3'  for STABLE BUILD TOOL VERSION*/
//        classpath 'com.android.tools.build:gradle:3.0.0-alpha7'
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'
        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin

        classpath 'io.fabric.tools:gradle:1+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
//        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build .gradle module app

apply plugin: 'com.android.application'

apply plugin: 'io.fabric'

repositories {
    maven {
        url 'https://maven.google.com'
    }
//    google()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.0'
    defaultConfig {
        applicationId "in.techware.lataxi"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 5
        versionName "1.0.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    /* Remove This to remove Crashlytics and Fabric */

    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
/*    compile('com.digits.sdk.android:digits:2.0.6@aar') {
        transitive = true;
    }*/
    implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation 'com.android.support:design:25.4.0'
    implementation 'com.android.support:recyclerview-v7:25.4.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.1'
    implementation 'com.android.support:cardview-v7:25.4.0'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.google.android.gms:play-services-maps:11.0.2'
    implementation 'com.google.android.gms:play-services-location:11.0.2'
    implementation 'com.google.android.gms:play-services-places:11.0.2'
    implementation 'com.google.firebase:firebase-auth:11.0.2'
    implementation 'com.google.firebase:firebase-messaging:11.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
    implementation 'com.google.code.gson:gson:2.8.0'
    testCompile 'junit:junit:4.12'
}







apply plugin: 'com.google.gms.google-services'
1
  • 1
    For me, the issue was that I had put the implementation in my project's build.gradle instead of module app build.gradle. Once I changed it worked fine.
    – Abhi
    Commented Oct 28, 2019 at 6:40

9 Answers 9

35

I had such a simple reason for this not working that I must post my answer to prevent anybody else going through this.

Don't put repositories and dependencies in the file called build.gradle (Project: YourProjectName)! There is a comment in that file that says:

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

Good job to whoever put that note in there. Instead, place your repositories and dependencies in the similarly named module file build.gradle (Module: app).

There should already be a dependencies function. You may need to add repositories function. In my case, it was:

repositories {
    maven { url "https://jitpack.io" }
}

This should let you sync and recognize implementation.

4
  • 3
    I wish this had stopped me going through the same - I just spent most of today trying to work out what was wrong, including reinstalling Android Studio, fiddling with my settings, installing new SDKs etc. The problem for me was that the comment you mention is inside the buildscript braces, so I thought it might be ok to put dependencies outside the braces. To reiterate: MAKE SURE you put things in the build.gradle for your app or module - not for the project.
    – M_M
    Commented Jul 23, 2019 at 14:31
  • This is exactly what I went through. It is worth noting that the SDK will suggest that you may need an update even though that was not the problem in our case.
    – iyrin
    Commented Jul 24, 2019 at 6:06
  • Right. I am coming to Android Studio from Visual Studio and AS is using "Project" like VS uses "Solution"; and AS is using "Module" like VS uses "Project" … at least this is what it seems to me.
    – pdschuller
    Commented Aug 17, 2019 at 14:09
  • This just saved me, had ignored the commented lines, until I found your answer. Thank you
    – Eric
    Commented Sep 25, 2020 at 5:46
29

To use the DSL implementation() you have to use:

  • The updated gradle plugin for Android 3.0.0
  • The gradle version 3.4 or later

Then in your build.gradle you have to use:

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta1'
    }
}

In your gradle-wrapper.properties

distributionUrl=\
  https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip

More detailed info here.

1
  • @MohammadAminMoordani this is some separate problem. It has nothing to do with your question. There is something wrong with your build.gradle file. You may wish to consider asking a separate question, Commented Aug 23, 2017 at 11:35
24

or if you don't want to update to the latest Gradle, go back to using DSL method compile() instead of implementation()

2
  • thanks a lot, your solution is quick and worked perfectly Commented Sep 5, 2018 at 13:55
  • 2
    compile() is expected to be deparacted by the end of 2018, so I wouldn't change it, and focus on fixing the error
    – brkeyal
    Commented Oct 3, 2018 at 10:07
21

As a beginner, I discovered that there's 2 build.gradle files

It's worth checking that you didn't add the line in the wrong file. I added mine in the project file whereas I should have added it in the module one.

You can see here the 2 build in the android view

1
  • This was the answer for me.
    – Belphegor
    Commented Oct 11, 2020 at 19:26
4

You using Turkish workspace, below change solves the problem

testImplementation -> testİmplementation,
androidTestImplementation -> androidTestİmplementation
androidTestImplementation -> androidTestİmplementation
3

implementation() has replaced compile() configuration, which will be DEPRECATED by the end of 2018.

In order to fix your errors and use it, you must update to Android Gradle Plugin 3.0.0 (or higher). As a result of this update, you also need to update Gradle to Gradle 4.1 (or higher). You also need to use Build Tools 26.0.2 (or higher), meaning to update your buildToolsVersion in your build.gradle, or just completely remove it from there (as, since 3.0.0, the minimum required version is used by default). You also need to update to Android Studio 3 (or higher) in order to use those advanced versions.

You can read about the changelog of android gradle plugin 3.0.0, the improved compile times, and more, here: https://developer.android.com/studio/releases/gradle-plugin#3-0-0

So how to update Android Gradle Plugin and Gradle?

OPTION 1: Manually

In your build.gradle find your gradle classpath and update version to gradle 3.0. Also, google() maven's repository should be added:

buildscript {
    repositories {
        jcenter()
        google()
    }

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

In gradle-wrapper.properties find your distributionUrl and update to:

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

OPTION 2: Through project properties (But notice the manual configuration WILL override it)

Go to File→Project Structure→Project

enter image description here

One last thing, you can also choose whether to replace compile() by implementation() or by api(). By default I would suggest just to use implementation(). You can read more about the differences here: https://developer.android.com/studio/build/dependencies

0
3

In my case it was just a typo. It was an extra sign "/" after one of rows

3
  • @TaslimOseni it doesn't matter
    – Neuron
    Commented Sep 1, 2019 at 8:01
  • 1
    My bad, I thought this was was a vague answer, didn't read through it properly. Commented Sep 1, 2019 at 8:24
  • Yes, the typo. "implmentation" instead of "implementation" in my case. Commented Dec 13, 2023 at 14:23
0

I ran into similar errors. when I tried to include the recyclerview dependencies from may build.gradle(Module: app) with a code like so.

//other build.gradle(Module: App) code above
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    implementation 'com.android.support:recyclerview-v7:25.3.1'
}

So the simple way I fixed this is by changing the code to this, where I changed the implement to compile while retaining every other code and their version numbers.

//other build.gradle(Module: App) code above
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:recyclerview-v7:25.3.1'
}

I hope this helps some one having similar issues. PS: The actual error was caused by implementation 'com.android.support:recyclerview-v7:25.3.1' and changing the code to compile 'com.android.support:recyclerview-v7:25.3.1' got it fixed.

0

in my case i add these line and issue resolved

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

Not the answer you're looking for? Browse other questions tagged or ask your own question.