> Cannot access class ’<class>’. Check yo...
# announcements
m
Cannot access class ’<class>’. Check your module classpath for missing or conflicting dependencies
What does this even mean exactly? I want to test code that depends on a certain library. But I cannot add that library to the test configuration, so I simply create some dummy classes with the same name & package name and mock them using mockk 🤔 Doesn’t seem to work though 😅
a
Yeah, it’s either a missing dependency or a conflict in your dependencies. Try accessing the class yourself from the IDE, then figure out from the path which dependency is providing that class
In my case when it happened, one of my libraries was using a latest version of a dependency, then gradle automatically used the latest version for the other libraries that are also dependent on that. Some libraries were using a class that was removed on the latest version. Solution is to either force a version or exclude these dependencies
Another weird issue if you’re doing Tests and Android; this happened to me with Android Studio 4+. There was nothing wrong with the classpath, and this error only shows up in Tests. Then I realized it only happens when I run the test using Android Studio 🙂 . Solution is to run it manually with gradle.
m
Thank you for your suggestions. The class is added with the same package name to my own project directly, so it’s impossible that it’s missing. My guess is that my class isn’t compatible with the one that the compiler is looking for and that the error message is just misleading. I’m on IntelliJ btw, not Android Studio.
a
But I cannot add that library to the test configuration,
Oh I completely missed this 🤦‍♂️ ; your solution should work, you might be missing something. Some debug libraries even have no-op versions but that’s typically used for release variant. Why can’t you add the library in your tests?
m
Because it’s added to the main compilation by a very complex setup done by a Gradle plugin which involves messing with generated class files and other fancy stuff. I cannot replicate that in the test configuration.