Configuration#canBeResolved returns true but resolution is not possible

Configurations <variant>CompileClasspath in Android projects having another module as dependency in fact cannot be resolved despite that canBeResolved is true.
The error:

Could not resolve all files for configuration ‘:app:debugCompileClasspath’.
More than one variant of project :lib matches the consumer attributes:

Sample project which reproduces this issue:

Build log:

Is it a bug in Gradle or Android Gradle Plugin?
Or maybe there is another way to resolve that configuration.