Gadle sync Error: Gradle DSL method not found: 'implementation()'

Viewed 477

I was developing a flutter application using Android Studio when I found out there is a problem with gradle sync.

I recently updated Android Studio and migrated the project to AndroidX (Refactor -> Migrate to Android X) and since then I always get this error while performing gradle sync. I get the same error using 'compile' instead of 'implementation' in my app/build.gradle file, in fact the last version of Kotlin is installed.

In particular this is the Error I get:

ERROR: Gradle DSL method not found: 'implementation()'
Possible causes:
The project 'android' 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).
Upgrade plugin to version 3.5.1 and sync project

The project '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

Now: I read this and tried to solve it following the 3 suggestions and this is what happens:

Upgrade plugin to version 3.5.1 and sync project:

Clicking on this suggestion I get this message: Unexpected Error

So I open android/build.gradle and add this line in the 'Dependencies' brackets in build script rule:

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

But the error keeps showing up.

The project 'android' may be using a version of Gradle that does not contain the method.

Open Gradle wrapper file

So I open gradle-wrapper.properties and this is what I find in it (I don't know if there's anything wrong here)

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip

And finally this is what happens when I click on

The build file may be missing a Gradle plugin.

Apply Gradle plugin

A list of plugins opens up and I really don't know which one I should implement

In addition this is my app/build.gradle file, so you can read where the 'implementation ()' method is called.

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.honoo"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    def core_version = '1.1.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "com.android.support:support-v4:28.0.0"
    implementation "androidx.core:core-ktx:$core_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

}

Furthermore this file also present a 'Cannot resolve symbol' error on 'GradleException' symbol.

I think this is due to the previous problem but I'm not sure about it.

I hope can land me an hand, maybe it's something I'm missing. Thank You.

1 Answers

Remove testImplementation and androidTestImplementations. Probably the problem will be solved.

Related