Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not resolve all task dependencies for configuration #1108

Open
Anigif opened this issue Jan 22, 2024 · 19 comments
Open

Could not resolve all task dependencies for configuration #1108

Anigif opened this issue Jan 22, 2024 · 19 comments

Comments

@Anigif
Copy link

Anigif commented Jan 22, 2024

Plugin version
1.28.0 (and 1.29.0)

Gradle version
8.2

JDK version
17

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version
Kotlin 1.9.21

(Optional) Android Gradle Plugin (AGP) version
8.2.1

Describe the bug
After bumping to 1.28.0 we get this error when building the project (for instance via build):

Could not determine the dependencies of task ':moduleA:extractDebugAnnotations'.
> Could not resolve all task dependencies for configuration ':moduleA:debugCompileClasspath'.
   > Could not resolve project :moduleB.
     Required by:
         project :moduleA
      > The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.2.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'. However we cannot choose between the following variants of project :moduleB:
          - projectHealthElements
          - resolvedDepsElements
        All of them match the consumer attributes:
          - Variant 'projectHealthElements' capability rootProject:moduleB:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.1')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Provides attribute 'dagp.internal.artifacts' with value 'project-health' but the consumer didn't ask for it
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about its usage (required compile-time)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')
          - Variant 'resolvedDepsElements' capability rootProject:moduleB:unspecified:
              - Unmatched attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.2.1')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Provides attribute 'dagp.internal.artifacts' with value 'resolved-deps' but the consumer didn't ask for it
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
                  - Doesn't say anything about its usage (required compile-time)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'androidJvm')

moduleA is here a regular module (with plugin com.android.library) and moduleB is a "wrapper" around an AAR file to be able to use it. The AAR file is included like this:

configurations.maybeCreate("default")
artifacts.add("default", file('someExternalLib.aar'))

This is not how the official documentation states it, but due to a weird bug this doesn't work for other reasons unfortunately.

I don't know if we can fix this in any other ways (is it possible to ignore dependencies or modules somehow?), so wanted to file this bug if you weren't aware of this. And for the record, it works fine for version 1.27.0.

@Anigif
Copy link
Author

Anigif commented Jan 27, 2024

Just for the record, I've now submitted a bug report for the solution stated by the official documentation. Hopefully it will get fixed, but it might still be worth figuring out why the other setup mentioned above doesn't work.

@autonomousapps autonomousapps added bug Something isn't working toolchain:android labels Feb 22, 2024
@autonomousapps
Copy link
Owner

I think that other configuration you create needs to have some metadata attached to it. If you provide a reproducer I can take a look and see if there's something I can do in DAGP.

@papo2608
Copy link

@autonomousapps here we go:
reproducer-issue-1108.zip

Thanks!

@autonomousapps
Copy link
Owner

I've just resolved another issue that looks at least superficially similar. Could you try the latest snapshot (wait at least an hour from when I post this message)?

@eduardbosch-jt
Copy link

Hey @autonomousapps,

Thanks for the update. Unfortunately, I've tested 1.31.1-SNAPSHOT and it didn't solve this issue. At least on my side.

@autonomousapps
Copy link
Owner

Alright, thanks! Looks like something that might be Android-specific.

@autonomousapps
Copy link
Owner

I was able to workaround this by adding this to the top of the "wrapper" module:

// wrapper-module/build.gradle
plugins {
  id("java")
}

I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?

@bidrohi
Copy link

bidrohi commented May 24, 2024

For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.

@autonomousapps
Copy link
Owner

For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.

What exactly throws a lint error?

@bidrohi
Copy link

bidrohi commented May 27, 2024

Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:

> Failed to notify project evaluation listener.
   > org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity
   > KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.

@autonomousapps
Copy link
Owner

Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:

> Failed to notify project evaluation listener.
   > org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity
   > KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.

@bidrohi this looks like a different issue. Could you file a new report?

@Anigif
Copy link
Author

Anigif commented May 29, 2024

I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?

We have an AAR-file that we have to import to our build somehow in order to be able to use it. We're okay about changing the way we import it (as long as it's reliable), but I'm not sure how you would add that as a dependency directly? Most other methods I've found is either outdated or not stable to use, unfortunately.

@autonomousapps
Copy link
Owner

I find the existence of such modules unusual -- what's the use-case? Why not just add the jar as a dependency to "normal" modules directly?

We have an AAR-file that we have to import to our build somehow in order to be able to use it. We're okay about changing the way we import it (as long as it's reliable), but I'm not sure how you would add that as a dependency directly? Most other methods I've found is either outdated or not stable to use, unfortunately.

Does a workaround like this help? Alternatively, you could publish that AAR to an internal artifact repo and consume it that way.

@Anigif
Copy link
Author

Anigif commented May 30, 2024

Does a workaround like this help?

Yeah, sorry forgot to give an answer here. I tried that, but I then wasn't able to access the content of the aar-file (imports of classes wasn't found anymore). It might be possible to do something like that, but I'm not an expert in gradle unfortunately.

Alternatively, you could publish that AAR to an internal artifact repo and consume it that way.

Might be an idea we could test out a bit. We are however several developers working on this project so we would need to have some automatic setup for this 🤔

@mr-thierry
Copy link

This works for me:

apply plugin: 'kotlin'

dependencies {
  api(files("someExternalLib.aar"))
}

@autonomousapps
Copy link
Owner

This works for me:

apply plugin: 'kotlin'

dependencies {
  api(files("someExternalLib.aar"))
}

This looks much more "normal" to me!

@bidrohi
Copy link

bidrohi commented Jun 2, 2024

For Android projects, it throws a lint error since adding AAR files directly misses the non-JVM parts of the archive.

What exactly throws a lint error?

Sorry.. I didn't share the lint error before:

Execution failed for task ':moduleA:bundleDebugLocalLintAar'.
> Error while evaluating property 'hasLocalAarDeps' of task ':moduleA:bundleDebugLocalLintAar'.
   > Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :moduleA project caused this error: <path to aar>

@bidrohi
Copy link

bidrohi commented Jun 2, 2024

Sorry doesn't look like I can get the same error as before. Now I get the following trying to sync the project after adding 1.32 version of the plugin:

> Failed to notify project evaluation listener.
   > org/jetbrains/kotlin/incremental/classpathDiff/ClassSnapshotGranularity
   > KotlinJvmAndroidCompilation with name 'compileDebugAndroidTest' not found.

@bidrohi this looks like a different issue. Could you file a new report?

Looks like it was broken with Kotlin 1.9.0 updating to 1.9.24 resolved this issue.

@Anigif
Copy link
Author

Anigif commented Jun 10, 2024

This works for me:

apply plugin: 'kotlin'

dependencies {
  api(files("someExternalLib.aar"))
}

The issue with this solution is that it unfortunately gives and error when linting as mentioned in the original post. I have submitted an issue (see first answer), but I unfortunately don't think that will be fixed any time soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants