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

Android: Analyzer fails because Gradle cannot choose between multiple project variants #4694

Closed
Tracked by #5066
MarcelBochtler opened this issue Nov 12, 2021 · 14 comments
Assignees
Labels
analyzer About the analyzer tool bug Issues that are considered to be bugs

Comments

@MarcelBochtler
Copy link
Member

When analysing a fairly large Android project, we often see issues with Gradle's dependency resolutions.

To reproduce:
Clone Owncloud's Android App: https://github.com/owncloud/android

Run the Analyzer: ort --info --stacktrace analyze -i android/ -o android/ort/analyzer

This causes the Analyzer to produce the following error:

14:10:57.164 [DefaultDispatcher-worker-3] ERROR org.ossreviewtoolkit.analyzer.managers.GradleDependencyHandler - Unresolved: ModuleVersionResolveException: Could not resolve project :owncloudDomain.
Caused by: AmbiguousConfigurationSelectionException: The consumer was configured to find a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we cannot choose between the following variants of project :owncloudDomain:
  - debugApiElements
  - debugRuntimeElements
  - ktlint
  - releaseApiElements
  - releaseRuntimeElements
All of them match the consumer attributes:
  - Variant 'debugApiElements' capability owncloud-android:owncloudDomain:unspecified declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Provides attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
  - Variant 'debugRuntimeElements' capability owncloud-android:owncloudDomain:unspecified declares a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Provides attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
  - Variant 'ktlint' capability owncloud-android:owncloudDomain:unspecified:
      - Unmatched attributes:
          - Provides its dependencies declared externally but the consumer didn't ask for it
          - Doesn't say anything about its usage (required a usage of 'kotlin-api')
          - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'common')
  - Variant 'releaseApiElements' capability owncloud-android:owncloudDomain:unspecified declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Provides attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
  - Variant 'releaseRuntimeElements' capability owncloud-android:owncloudDomain:unspecified declares a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
      - Unmatched attributes:
          - Provides attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' but the consumer didn't ask for it
          - Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'release' but the consumer didn't ask for it
@MarcelBochtler MarcelBochtler added bug Issues that are considered to be bugs analyzer About the analyzer tool labels Nov 12, 2021
@MarcelBochtler
Copy link
Member Author

A possible way to fix this would be to offer an optional Analyzer option to select the variant which should be analysed.

@sschuberth
Copy link
Member

A possible way to fix this would be to offer an optional Analyzer option to select the variant which should be analysed.

A similar (package-manager-specific) option (in .ort.yml) could then also be used to address #1774 by specifying the Maven profile to use.

@tsteenbe
Copy link
Member

tsteenbe commented Nov 12, 2021

@sschuberth @MarcelBochtler Did you just enabled the Analyzer to use labels? Could we instead use a specific label keys to specify gradle variant/maven profile to analyze?

@sschuberth
Copy link
Member

Whatever mechanism we use, IMO it needs to be one that is configurable along with the project's source code. We could also allow to set labels in .ort.yml actually, so things like the "application type" (which AFAIK HERE tracks as labels) could also be configured in the project itself, rather than a belonging Jira ticket or Confluence page.

@sschuberth

This comment was marked as outdated.

@sschuberth

This comment was marked as outdated.

@sschuberth
Copy link
Member

sschuberth commented Jul 5, 2022

@sschuberth

This comment was marked as duplicate.

@sschuberth

This comment was marked as duplicate.

sschuberth added a commit that referenced this issue Feb 27, 2023
Previously, failures to look up remote artifacts were unconditionally
cached as empty artifacts. While it is hard to reliably determine the
root cause of a failed lookup, in the case that all candidate URLs do
not end with a known extension it is very likely that ORT ran into a bug
in the context of #4694. Ease debugging such cases by not anymore
caching failed lookups due to missing file extensions, and generally
improve the logging when returning an empty remote artifact.

Signed-off-by: Sebastian Schuberth <[email protected]>
sschuberth added a commit that referenced this issue Feb 27, 2023
Previously, failures to look up remote artifacts were unconditionally
cached as empty artifacts. While it is hard to reliably determine the
root cause of a failed lookup, in the case that all candidate URLs do
not end with a known extension it is very likely that ORT ran into a bug
in the context of #4694. Ease debugging such cases by not anymore
caching failed lookups due to missing file extensions, and generally
improve the logging when returning an empty remote artifact.

Signed-off-by: Sebastian Schuberth <[email protected]>
sschuberth added a commit that referenced this issue Feb 27, 2023
Previously, failures to look up remote artifacts were unconditionally
cached as empty artifacts. While it is hard to reliably determine the
root cause of a failed lookup, in the case that all candidate URLs do
not end with a known extension it is very likely that ORT ran into a bug
in the context of [1]. Ease debugging such cases by not anymore
caching failed lookups due to missing file extensions, and generally
improve the logging when returning an empty remote artifact.

[1]: #4694

Signed-off-by: Sebastian Schuberth <[email protected]>
sschuberth added a commit that referenced this issue Feb 27, 2023
Previously, failures to look up remote artifacts were unconditionally
cached as empty artifacts. While it is hard to reliably determine the
root cause of a failed lookup, in the case that all candidate URLs do
not end with a known extension it is very likely that ORT ran into a bug
in the context of [1]. Ease debugging such cases by not anymore
caching failed lookups due to missing file extensions, and generally
improve the logging when returning an empty remote artifact.

[1]: #4694

Signed-off-by: Sebastian Schuberth <[email protected]>
@sschuberth sschuberth pinned this issue Mar 22, 2023
@sschuberth sschuberth self-assigned this Mar 27, 2023
@sschuberth sschuberth unpinned this issue Apr 14, 2023
@sschuberth
Copy link
Member

I just confirmed that the GradleInspector can successfully analyze https://github.com/owncloud/android, see the attached analyzer result. So this specific issue can be closed.

@brueggenthies-ams
Copy link

@sschuberth after switching to the new Gradle-Inspector i could also successfully analyze my android project. However i struggle to scan through the project, because the sources for all androidx.xyz libraries from the Android Jetpack Project cannot be resolved. This is probably due to bad metadata in the maven artifact.

Because the AndroidX Libraries are developed inside a big mono repo, you cannot match a specific library version against a revision inside the repository. The sources are provided as jars for each library version.

Is it correct to add these information via the curations.yml file, to prevent failing source downloads?

@sschuberth
Copy link
Member

However i struggle to scan through the project, because the sources for all androidx.xyz libraries from the Android Jetpack Project cannot be resolved.

Also see #5105 in that context.

This is probably due to bad metadata in the maven artifact.

Correct.

Because the AndroidX Libraries are developed inside a big mono repo, you cannot match a specific library version against a revision inside the repository

That's not completely true, as you could leverage the VcsInfo's path property to point at the subdirectory in a monorepo containing the source code of that library:

/**
* The path inside the VCS to take into account. If the VCS supports checking out only a subdirectory, only this
* path is checked out.
*/
val path: String = ""

Is it correct to add these information via the curations.yml file, to prevent failing source downloads?

Yes, I'd probably curate author and concluded license, and enable the skipConcluded scanner option as suggested here.

@ksg97031
Copy link
Contributor

I'll edit this comment to collect a list of other Gradle dependency analysis tools, to look at how they're avoiding the AmbiguousConfigurationSelectionException and AmbiguousVariantSelectionException (ticked ones have been looked at):

Additional information:

Hello sschuberth, I'm looking for a way to choose build variants in the analyzer to speed up processing. Currently, we can't select build variants, so are you suggesting we use gradle-inspector instead?

@sschuberth
Copy link
Member

Currently, we can't select build variants, so are you suggesting we use gradle-inspector instead?

Using gradle-inspector will also not allow you to limit analysis to specified build variants for performance reasons; that would go against one of the fundamental principles of ORT to not "hide" information from the user. Instead, we always analyze everything, and later on allow to filter down information (e.g. via scope excludes and other means) to what is relevant in the respective context.

However, if performance is such a big issue in your case, one could think about a feature that indeed really omits build variants (or scopes, as a more general term) from analysis, but clearly documents as part of the analyzer result what was not analyzed. If you're interested in such a feature, please file a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer About the analyzer tool bug Issues that are considered to be bugs
Projects
None yet
Development

No branches or pull requests

5 participants