1
votes

How it happened

  • the unit test class works fine initially.
  • I encountered this issue after removing the C:\users\my_username\.Android\.gradle folder, and redirecting gradle dir in Android Studio to E:\Android_file_folder\gradle.

Since then, my unit tests cannot be compiled any more, although I have tried the following,

  • Disabled work offline option
  • Adding implementation 'junit:junit:4.12' to classpath
  • In Android Studio, File -> Invalidate Caches/Restart
  • Clean project and rebuild project

Problem Symptoms,

  • annotation in unit tests (@Test, @Before, @After) is red. When pressing Alt+Enter over these annotaion, the pop up menu keeps giving me the option to add Junit4 to classpath.
  • I check the gradle folder ( E:\Android_file_folder\gradle\caches\transforms-1\files-1.1\junit-4.12.jar\2509a789951ff3e52dd4785783415e3f ") it is empty.

Can you show me any additional steps I can try to resolve this issue?

1

1 Answers

2
votes

This issue is resolved by doing the following,

  • deleting the .gradle directory in the project directory.
  • deleting the .idea\libraries
  • sync gradle

It appeared that despite changing the service directory under File>Settings>Build,Execution,Deployment>Gradle>Service Directory Path alone without deleting the mentioned folders doesn't stop the project from looking in the old directory.