java.lang.NoClassDefFoundError:android and junit test

你说的曾经没有我的故事 提交于 2019-11-28 22:40:41
LoPoBo

Not sure if I had the same problem as you but I am using gradle and for some reason the tests just wouldn't run anymore, with the same error as you had. I tried cleaning and rebuilding but to no avail. After hours of frustration and trying to find an answer I came across the simple solution in a GitHub thread:

I resolved this issue by removing the .gradle folder in my project and rebuilding the project.

(thanks to vpetrov)

You can run ./gradlew clean test in the terminal.

Fixed the issue by following these steps --

1.Open module level build.gradle file, go to dependencies, go to this line --

testImplementation 'junit:junit:4.12'

2.Change the junit version to anything else below it (like 4.10)

testImplementation 'junit:junit:4.10'

3.Sync project

4.The issue fixed at this point in my case

5.Set the junit version back to what it was before (4.12 in my case) if you want

testImplementation 'junit:junit:4.12'

6.Sync project

Changing the junit version and syncing project worked in my case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!