我正在尝试在android studio中构建应用程序,但遇到的错误只是最近才开始出现。据我所知,我尚未更改任何设置或修改任何会导致错误发生的系统文件。我尝试重新安装android studio,但错误仍在发生,所以我开始认为这是编码问题。错误如下:

Gradle task[clean, :app:generateDebugSources,:app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :appcompileDebugSources, :app:complieDebugSources, :app: compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
  C:\Users\Stuart\Documents\TourApp\App\src\androidTest\java\com\example\android\tourapp\ExampleInstrumentedTest.java
error: package android.support.test does not exist
error: package android.support.test.runner does not exist
error: package android org.junit does not exist
error: package android org.junit.runner does not exist
error: package android org.junit does not exist
error: cannot find symbol class RunWith
error: cannot find symbol class Test
error: cannot find symbol variable InstrumentationRegistry
Execution failed for task ':app:compileDebugAndroidTestJavaWithJavac'.
Compilation failed; see the compiler error output for details.

任何想法可能是什么原因造成的?

最佳答案

尝试在app/build.gradle文件的“dependencies”部分下添加以下行

dependencies {

     testImplementation 'junit:junit:4.12'
     //androidTestCompile 'junit:junit:4.12'
}

另外,您可以使用 androidTestCompile 'junit:junit:4.12' 作为替代。

10-05 21:00
查看更多