简体   繁体   中英

Gradle error Android Studio

I'm trying to build a project but it keeps giving me this gradle error I have upgraded my gradle 3.3 and my android plugin version to 2.3.3 but it's still giving me error Any help would be appreciated Error:

Error:(40, 0) Gradle DSL method not found: 'implementation()' Possible causes:

  • The project 'sms-mining-android' may be using a version of the Android Gradle plug-in that does not contain the method (eg 'testCompile' was added in 1.1.0). Upgrade plugin to version 2.3.3 and sync project
  • The project 'sms-mining-android' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • Event Log: Gradle sync failed: Could not find method implementation() for arguments [com.android.support.constraint:constraint-layout:1.0.2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

    build.gradle file:

    buildscript {
    ext.kotlin_version = '1.1.2-5'
    ext.support_lib_version = '25.3.1'
    ext.junit_version = '4.12'
    ext.constraint_layout_version = '1.0.2'
    ext.rxjava_version = '1.1.3'
    ext.rxandroid_version = '1.1.0'
    ext.mpchart_version='v3.0.2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }}
    
    allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
    }
    
    task clean(type: Delete) {
    delete rootProject.buildDir
    }
    

    gradle-wrapper.properties file:

     #Mon Jun 19 10:49:52 IST 2017
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    

    try this gradle configuration ,it works for me :

    buildscript {
    ext.kotlin_version = '1.1.2-5'
    ext.support_lib_version = '25.3.1'
    ext.junit_version = '4.12'
    ext.constraint_layout_version = '1.0.2'
    ext.rxjava_version = '1.1.3'
    ext.rxandroid_version = '1.1.0'
    ext.mpchart_version = 'v3.0.2'
    ext.realm_version = '3.3.2'
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:$realm_version"
    
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    

    }

    allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven { url "https://jitpack.io" }
    }
    

    }

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

    }

    add maven { url 'https://maven.google.com' } in repositories

    And use Android studio 3.0 preview for this configuration.

    simply add this into your project level gradle

    classpath 'com.android.tools.build:gradle:3.0.0-alpha4'

    it is because you have implementation() method in your app level gradle file

    This is an answer tested and works on Android Studio 3.0 Canary 6.

    Upgrade gradle version in your project level gradle classpath to a more recent one.

    Of what I understand regarding the official documentation about gradle / gradle plugin version compatibility it should work with gradle plugin version 2.3.3 and gradle version 3.3 (anybody correct me if I'm wrong):

    在此输入图像描述

    Anyway I had to upgrade the plugin to version 3.0.0-alpha6 to get rid of the error. To do so make this change in project level build.gradle :

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

    Note I had a different gradle version than yours in my gradle-wrapper.properties (4.1):

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

    So if you change these both lines in these both files it should works. Note that com.android.tools.build:gradle:3.0.0-alpha4 suggested by @Narendra kumawat didn't work for me, I had to use alpha6.

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM