微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

嗨,我正在使用 AndroidStudio中的gradle测试我的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()
    }
}

解决方法

正如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')
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐