【问题标题】:Gadle sync Error: Gradle DSL method not found: 'implementation()'Gadle 同步错误:未找到 Gradle DSL 方法:'implementation()'
【发布时间】:2020-02-21 04:34:57
【问题描述】:

当我发现 gradle sync 存在问题时,我正在使用 Android Studio 开发 Flutter 应用程序。

我最近更新了 Android Studio 并将项目迁移到 AndroidX(重构 -> 迁移到 Android X),从那时起我在执行 gradle 同步时总是收到此错误。我在 app/build.gradle 文件中使用 'compile' 而不是 'implementation' 得到同样的错误,实际上安装了 Kotlin 的最新版本。

尤其是我得到的错误:

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

现在: 我阅读了这篇文章并尝试按照 3 条建议解决它,结果如下:

将插件升级到 3.5.1 版本并同步项目:

单击此建议我收到此消息:Unexpected Error

所以我打开 android/build.gradle 并将这一行添加到构建脚本规则的“依赖项”括号中:

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"
    }
}

但错误不断出现。

项目“android”可能正在使用不包含该方法的 Gradle 版本。

打开 Gradle 包装文件

于是我打开gradle-wrapper.properties,发现里面是这个(不知道这里有没有问题)

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

最后,当我点击

时会发生这种情况

构建文件可能缺少 Gradle 插件。

应用 Gradle 插件

一个插件列表打开了,我真的不知道我应该实现哪个

此外,这是我的 app/build.gradle 文件,因此您可以查看调用“implementation ()”方法的位置。

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"

}

此外,此文件还在“GradleException”符号上显示“无法解析符号”错误。

我认为这是由于之前的问题,但我不确定。

我希望能帮我一把,也许这是我缺少的东西。谢谢。

【问题讨论】:

    标签: android android-studio gradle kotlin flutter


    【解决方案1】:

    删除 testImplementation 和 androidTestImplementations。 说不定问题就解决了。

    【讨论】:

    • 没办法。不幸的是,这并不能解决任何问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    相关资源
    最近更新 更多