Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter android android

Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter


Finally found it. It's in the Run/Debug Configurations dialog. Disabled JUnit and it compiles again.


Usually this problem is caused because of wrong test type: Junit instead of Android TestSelect Android test instead of JUnitSelect Android test instead of JUnit


For standard JUnit tests, you are missing the JUnit library, try adding this in build.gradle:

dependencies {    ...    testCompile 'junit:junit:4.12'    ...}

And make sure you are putting the tests in the "test" directory parallell to the "main" package (instrumentation tests goes into "androidTest", but that is different setup).