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

False-positive unused dependencies error for resources in XML files #420

Closed
eugene-krivobokov opened this issue Jun 17, 2021 · 6 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@eugene-krivobokov
Copy link
Contributor

eugene-krivobokov commented Jun 17, 2021

Build scan link

Plugin version

0.73.0

UPD: 0.77.0

Gradle version

6.9

(Optional) Android Gradle Plugin (AGP) version

4.1.2

Describe the bug

False-positive unused dependencies error when Android resources are used only in XML resources.

To Reproduce
Steps to reproduce the behavior:

  1. Checkout branch dep-analyzer-res-in-xml-reproducer
  2. ./gradlew -p subprojects :android-lib:snackbar-proxy:projectHealth

Expected behavior

Detect usages of resources

UPD: See subprojects/android-lib/snackbar-proxy/src/main/res/drawable/ic_pin.xml file. It uses android:fillColor="?themeColor" from :android-lib:ui-lib.

Additional context

  • android.nonTransitiveRClass=true
  • In code it works, commented it in a sample.
@autonomousapps
Copy link
Owner

Interesting, thanks for the reproducer. The plugin does attempt to detect resources used by other resources, but it looks like it is failing here.

@autonomousapps autonomousapps added the bug Something isn't working label Jun 17, 2021
@autonomousapps autonomousapps added this to the 1.0 milestone Jun 17, 2021
@konnovdev
Copy link

konnovdev commented Aug 6, 2021

I'm also facing the same problem when i'm declaring dependency on another module only to use xml resources from that module

@autonomousapps
Copy link
Owner

I realized that this issue report is lacking some important detail. It's unclear what "detect usage of resources" means. I cloned that branch and ran the indicated task and saw this

> Task :android-lib:snackbar-proxy:projectHealth
Unused dependencies which should be removed:
- implementation(project(":android-lib:ui-lib"))

So I should infer that :android-lib:ui-lib contains resources that are being used?

@eugene-krivobokov
Copy link
Contributor Author

Sure, see a comment "This usage is not detected" in subprojects/android-lib/snackbar-proxy/src/main/res/drawable/ic_pin.xml file. It uses android:fillColor="?themeColor" from :android-lib:ui-lib module.

How to check it:

  • Remove dependency to :android-lib:ui-lib from :android-lib:snackbar-proxy module
  • ./gradlew -p subprojects :android-lib:snackbar-proxy:assembleRelease
  • AAPT fails:
':android-lib:snackbar-proxy:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > 1 exception was raised by workers:
     com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
     /.../avito-android-github/subprojects/android-lib/snackbar-proxy/src/main/res/drawable/ic_pin.xml:9: AAPT: error: resource attr/themeColor (aka com.avito.android.snackbar.proxy:attr/themeColor) not found.

@eugene-krivobokov
Copy link
Contributor Author

I've updated the issue description accordingly and rechecked with 0.77.0.

@autonomousapps
Copy link
Owner

I have resolved this specific case (using an attr from another module) with the associated PR, but I haven't tried to fix the problem more comprehensively. Android resource linking is very complicated and I'd rather solve it on a case-by-case basis, with actual use-cases, then try to figure it all out a priori.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants