【问题标题】:Gradle DSL method not found: 'testCompile()'找不到 Gradle DSL 方法:'testCompile()'
【发布时间】:2017-10-27 23:51:56
【问题描述】:

我正在尝试在 Android Studio 中构建一个项目。当我运行该应用程序时,我收到此错误:

Error:(10, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:
-The project 'AccurateCalculator' 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 2.3.2 and sync project.The project 'AccurateCalculator' 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

项目的build.grade有如下代码:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

模块的build.gradle代码如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 17
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "calculator.app"
        minSdkVersion 14
        targetSdkVersion 17
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile files('libs/achartengine.jar')
    compile files('libs/arity-2.1.6.jar')
    compile files('libs/ejml-0.21.jar')
    compile files('libs/slider.jar')
}

【问题讨论】:

    标签: android android-studio gradle android-gradle-plugin build.gradle


    【解决方案1】:

    正如警告所示,将插件升级到 2.3.2 应该可以解决问题:

    classpath 'com.android.tools.build:gradle:2.3.2'
    

    【讨论】:

      【解决方案2】:

      对于遇到此问题且无法通过更改 gradle 文件来解决此问题的任何人:

      我的 MAC 格式化后遇到了这个问题。对我来说,解决方法是将操作系统语言改回英文。我建议尝试一下。

      For changing OS language (MAC)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-16
        • 1970-01-01
        • 2019-10-21
        • 2015-11-19
        • 2015-03-29
        • 2015-01-20
        • 2015-01-10
        相关资源
        最近更新 更多