Android gradle src/androidTest/res/layout/mylayout.xml not found in mypackage.R

前端 未结 2 1245
萌比男神i
萌比男神i 2021-02-19 10:36

I\'m writing my unit tests using gradle in Android Studio. I have the tests located in:

src/androidTest/java

That works just fine. N

相关标签:
2条回答
  • 2021-02-19 11:18

    For me, the solution was to put the source files in src/androidTest/java and the resource files in src/androidTest/res. Those are the standard locations, so you don't need to edit anything in gradle.build.

    Plus, rename your R import from

    import com.mycompany.myappname.R;
    

    to

    import com.mycompany.myappname.test.R;
    

    Source: Configuring res srcDirs for androidTest sourceSet

    0 讨论(0)
  • 2021-02-19 11:34

    I found the solution, add this to your build.gradle file.

    sourceSets {
        androidTest {
            java.srcDirs = ['src/androidTest/src']
            resources.srcDirs = ['src/androidTest/src']
        }
    }
    
    0 讨论(0)
提交回复
热议问题