Gradle DSL method not found: 'implementation()'

我的未来我决定 提交于 2019-11-29 03:12:20

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.

John Ramos

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

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 (Projet: 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.

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

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

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

You using Turkish workspace, below change solves the problem

testImplementation -> testİmplementation,
androidTestImplementation -> androidTestİmplementation
androidTestImplementation -> androidTestİmplementation
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!