본문 바로가기
안드로이드

The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin 에러 해결

by 코딩히어로 2022. 4. 8.
728x90

안드로이드 스튜디오 프로젝트가 AndroidX로 업데이트되기 이전의 프로젝트를

최신 안드로이드 스튜디오에서 빌드할 시 다음과 같은 에러가 발생할 수 있습니다.

 

The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something

 

해당 에러는 build.gradle 파일에 instrumentTest.setRoot('tests') 라고 되어있는 부분이

문제가 되는 것인데 최신버젼으로 업데이트되면서 해당 문구는 사용할 수 없고

instrumentTest를 androidTest로 변경해서 사용해야 합니다.

 

변경 전

android {
    compileSdkVersion 31
    buildToolsVersion "31.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

 

변경 후

android {
    compileSdkVersion 31
    buildToolsVersion "31.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        androidTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

 

해당 내용 적용 후 Sync Now를 클릭하고 앱을 Build 하게 되면

에러 문구 없이 해결된 것을 볼 수 있습니다.

 

728x90
반응형

댓글