The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin

Solution 1:

instrumentTest has been deprecated and does not work with modern Gradle versions - which you probably updated in your project when upgrading Android Studio.

Replace instrumentTest with androidTest and it'll work.

Solution 2:

Replace instrumentTest by androidTest as example below

android {
    buildToolsVersion "27.0.3"
    compileSdkVersion 24
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        androidTest.setRoot('tests')
    }
}

Solution 3:

Try change distributionUrl in you gradle/wrapper/gradle-wrapper.properties to last vesion:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

clean project and "Invalidate Cache/Restart" in File menu after this

Solution 4:

Try with the Android Studio 3.1.2 update, which has a fix for this bug: https://developer.android.com/studio/releases/index.html#3-1-0