Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : Gradle 'HelloWorld' project refresh failed: Build script error, unsupported Gradle DSL method found: 'setRoot()'!

Hi I am doing testing of my android app using gradle in the AndroidStudio. I am using this framework RoboLectric for doing it all.

It is giving me an error when I sync it with gradle files. Guys, share your views for this problem.

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

In the folder app, there is build.gradle, this is which I have right now

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.+'
}

In the HelloWorld, there is another build.gradle where I have

// 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()
    }
}
like image 878
N Sharma Avatar asked Mar 21 '23 07:03

N Sharma


1 Answers

As Peter suggested in the comment to declare the sourceSets inside the android { .... }.

It worked for me.

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')
    }
}
like image 161
N Sharma Avatar answered Mar 23 '23 15:03

N Sharma