Need help on debugging No matching variant error

I am trying to build an android SDK but I get this error while syncing.

A problem occurred configuring project ':mymodule'.
> Could not resolve all files for configuration ':mymodule:classpath'.
   > Could not resolve mypkg:mylib:1.0.0.
     Required by:
         project :mymodule
      > No matching variant of mypkg:mylib:1.0.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5.1' but:
          - Variant 'apiElements' capability mypkg:mylib:1.0.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')
          - Variant 'runtimeElements' capability mypkg:mylib:1.0.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '7.5.1')

I am using Gradle 7.5.1 and as far as possible specified usage of Java 11. Any idea how to debug further or fix this issue?

Hard to say without seeing the build.
But I’d say you are running Gradle with Java 8 and try to use the plugin mypkg:mylib that is compiled with minimum version Java 11.

Thanks for your reply. Forcing mylib to use Java 8 does solve the problem. However, what this means “Gradle with Java 8”? A given Gradle version supports a range of Java versions. How do I know “Java 8” is used here? For mylib, I would use android → compileOptions → source/target compatibility.

Gradle is a Java program.
You run it with some Java version.
I guessed that you are running it with Java 8 when getting that error while trying to use some plugin that was compiled with minimum Java version 11.