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

dependencyCheckAnalyze fails in Android project with more than one modules #71

Closed
gmetal opened this issue Jan 8, 2018 · 14 comments
Closed
Labels

Comments

@gmetal
Copy link

gmetal commented Jan 8, 2018

After updating an Android application to Gradle 4.1, the dependencyCheckAnalyze task has started failing. It appears that it is unable to handle multiple modules. I have created a sample app that demonstrates the problem: https://github.com/gmetal/sample-dependency-check-app
If you run the dependencyCheckAnalyze task, you'll see something like the following:

./gradlew dependencyCheckAnalyze

> Task :app:dependencyCheckAnalyze
Verifying dependencies for project app


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dependencyCheckAnalyze'.
> Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
   > More than one variant of project :mylibrary matches the consumer attributes:
       - Configuration ':mylibrary:debugApiElements' variant android-aidl:
           - Found artifactType 'android-aidl' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
           - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':mylibrary:debugApiElements' variant android-classes:
           - Found artifactType 'android-classes' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
           - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':mylibrary:debugApiElements' variant android-manifest:
           - Found artifactType 'android-manifest' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
           - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':mylibrary:debugApiElements' variant android-renderscript:
           - Found artifactType 'android-renderscript' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
           - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
       - Configuration ':mylibrary:debugApiElements' variant jar:
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
           - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
           - Required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
1 actionable task: 1 executed
@jeremylong jeremylong added the bug label Jan 16, 2018
@jeremylong
Copy link
Collaborator

Thanks for the bug report. I will try to look at this in the next two weeks.

@aleksandr-deich
Copy link

Any updates?

@mauricegavin
Copy link

We're also facing this issue. Is there anything we can do to help?

@adjorno
Copy link

adjorno commented Feb 22, 2018

Hope it will be fixed soon.

@andyhermann
Copy link

andyhermann commented Feb 23, 2018

My workaround for this issue:
when defining the module depdendency add a configuration
implementation project(path: ':domain', configuration: 'default')
However this has the side effect that Android Studio does not resolve links to domain code directly to the source code but instead shows the classes.

@adjorno
Copy link

adjorno commented Feb 23, 2018

https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#variant_dependencies

I am facing this kind of errors if I add configuration:
Error:Unable to resolve dependency for ':app@debug/compileClasspath':
Could not resolve project :library.
Error:Unable to resolve dependency for ':app@release/compileClasspath':
Could not resolve project :library.

@jeremylong
Copy link
Collaborator

All - I'm still researching this. Unfortunately, I am not seeing a quick fix.

@jeremylong
Copy link
Collaborator

I've looked at several other plugins that deal with project dependencies and I have not yet found a solution. Most other plugins obtain the ResolvedDependency objects which works if you are just gathering the coordinates of the dependency; however, dependency-check uses the actual JAR file. When attempting to obtain the ResolvedArtifact objects is where the error occurs. I have asked a question on SO and will likely be following up with gradle support shortly.

@jeremylong jeremylong added question and removed bug labels Jul 10, 2018
@jeremylong
Copy link
Collaborator

I just found the solution to the problem. See https://stackoverflow.com/a/44207419/1995422

In the sample project's app/gradle.build#L24 change

implementation project(':mylibrary')

To

implementation project(path: ':mylibrary', configuration: 'default')

Explicitly setting the configuration on the project reference resolves the error. Additional enhancements are being made to better support Android AAR dependencies.

@jeremylong
Copy link
Collaborator

I should point out that the solution to this (which I outlined above) was previously provided #71 (comment) - I wanted to exhaust some avenues of research before finalizing this as the best answer. I believe there might be an underlying issue between gradle and the android sdk that causes this problem as @andyhermann pointed out - this does cause an issue in android studio.

@jeremylong
Copy link
Collaborator

I did open a ticket with gradle (gradle/gradle#5953) to see if they believe there is an underlying issue.

@gmetal
Copy link
Author

gmetal commented Jul 12, 2018

I had a quick look at the change your are proposing. It seems to resolve the errors you get when running the dependencyCheckAnalyze. However, as others have pointed out, if you attempt to sync the project in Android Studio (used 3.2-beta3), it fails.

On the sample project though, simply building the application (e.g. ./gradlew assembleDebug) on the project root folder once, allows AS to figure out what it is missing and sync the project. I even managed to build the APK and run it in a real device.

After trying the same workaround in a more complex project with multiple modules, and many dependencies, I could not get the ./gradlew assembleFlavourDebug step to complete properly.

@jeremylong jeremylong added bug and removed question labels Jul 13, 2018
@jeremylong
Copy link
Collaborator

The ticket with the gradle team pointed me in a different direction (see gradle/gradle#5953 (comment)). I am still trying to fully understand some of the new/incubating APIs but hope to have something soon.

@lock
Copy link

lock bot commented Sep 27, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Sep 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants