错误:Gradle'HelloWorld'项目刷新失败:构建脚本错误,找不到支持的Gradle DSL方法:'setRoot()'!

时间:2014-03-10 10:12:47

标签: android gradle android-studio robolectric

您好我正在使用gradle中的AndroidStudio测试我的Android应用。我正在使用这个框架RoboLectric来完成这一切。

当我与gradle文件同步时,它给了我一个错误。伙计们,分享您对此问题的看法。

Gradle settings
3:35:14 PM Gradle 'HelloWorld' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'setRoot()'!
Possible causes could be:  
- you are using Gradle version where the method is absent 
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
Gradle settings

在文件夹应用程序中,有build.gradle,这是我现在拥有的

apply plugin: 'android'
apply plugin: 'android-test'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

sourceSets {
    instrumentTest.setRoot('src/test')
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])

    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    testCompile 'com.squareup:fest-android:1.0.+'
    instrumentTestCompile 'junit:junit:4.10'
    instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}

在HelloWorld中,还有另一个build.gradle,我有

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
        classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

1 个答案:

答案 0 :(得分:7)

正如Peter在评论中建议的那样,在android {....}中声明sourceSets。

它对我有用。

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets {
        instrumentTest.setRoot('src/test')
    }
}
相关问题