skip to Main Content

I’m encountering an issue when building my Android project using gradlew with Java 17. The error message I’m getting is:

"Could not resolve androidx.navigation:navigation-safe-args-gradle-plugin – ‘a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 13’"

However, when I build and run the application through Android Studio, everything works fine. This error also appears in my Git Actions workflow as part of the CI process.

I need Java version 17 for my project. Can anyone help me understand why this error occurs when using gradlew and how to resolve it?

Additionally, I’m curious about the exact command that Android Studio is running, as the project builds successfully with the GUI. Understanding that command might provide insights into the issue.

the full info :

MacBook-Pro:My-Android me$ ./gradlew
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'My-Android'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0.
     Required by:
         project :
      > No matching variant of androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 13, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.1' but:
          - Variant 'apiElements' capability androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 13
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1')
          - Variant 'runtimeElements' capability androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 13
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1')
          - Variant 'sourcesElements' capability androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 13)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.1')

2

Answers


  1. I’m not sure if it will work for you or if you found another solution, but for me it was updating my CircleCI image in my code here image: cimg/android:2024.01. Docs found
    here https://circleci.com/developer/images/image/cimg/android

    Login or Signup to reply.
  2. I spent the best part of a day figuring out the issue – note from the docs:

    How do I choose which JDK runs my Gradle builds? If you run Gradle
    using the buttons in Android Studio, the JDK set in the Android Studio
    settings is used to run Gradle. If you run Gradle in a terminal,
    either inside or outside Android Studio, the JAVA_HOME environment
    variable (if set) determines which JDK runs the Gradle scripts. If
    JAVA_HOME is not set, it uses the java command on your PATH
    environment variable.

    For the most consistent results, make sure you set your JAVA_HOME
    environment variable, and Gradle JDK configuration in Android Studio
    to that same JDK.

    Note: If you run a Gradle command in the Android Studio Terminal by
    right-clicking and selecting Run highlighted command using the IDE
    then it uses the JDK in the Android Studio settings, not JAVA_HOME.

    The issue is going to be that your JAVA_HOME environment variable is pointing to something that is not Java 17, which gradle from the terminal uses, as opposed to the UI buttons in Android Studio. Also note, in Android Studio under Settings > Build, Execution, Deployment > Build Tools > Gradle there is a dropdown to choose the Gradle JDK. I (and almost certainly you) have this set to the default JetBrains Runtime – currently at 17.0.7.

    But one of the options shows JAVA_HOME, and reports it as 17.0.7 (see image): enter image description here

    For me this JAVA_HOME entry is incorrect, JAVA_HOME is in fact pointing to OpenJDK 11 on this mac which it is finding on my PATH, even though Android Studio shows it’s the jbr jvm.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search