Create a class name ErrorMatcher inside your test package with below code:
public class ErrorMatcher {
@NonNull
public static Matcher<View> withError(final String expectedErrorText) {
Checks.checkNotNull(expectedErrorText);
return new BoundedMatcher<View, ...