autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.82k stars 121 forks source link

Declared styleable attributes not accounted for #664

Closed ZacSweers closed 2 years ago

ZacSweers commented 2 years ago

Build scan link

Plugin version

1.1.0

Gradle version

7.4.2

(Optional) Android Gradle Plugin (AGP) version

7.1.3

Describe the bug

Consider this styleable declaration from androidx.swiperefreshlayout

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:swiperefreshlayout/swiperefreshlayout/src/main/res-public/values/attrs.xml;l=19

I found a case where a library depends on this library and defines a value for this attribute like so

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.SlackKit.NoActionBar" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar.Bridge">
        ...
        <item name="swipeRefreshLayoutProgressSpinnerBackgroundColor">?android:attr/colorBackground</item>
    </style>
</resources>

DAGP misses this usage and removes the library as unused

To Reproduce Steps to reproduce the behavior: See above

Expected behavior

I'd expect it to properly detect this

Additional context

autonomousapps commented 2 years ago

@ZacSweers is the only connection between this consumer and the swipe refresh layout library that the library has a public attr type named "swipeRefreshLayoutProgressSpinnerBackgroundColor" and the consumer defines a value for an item with that same name? In other words, is this just a matter of string matching?

I should note that the plugin already understands that the library defines this attr. In other contexts, it can already detect that this attr is used by a consumer. It's a peculariaty of the custom matching algorithm that it currently misses this usage. So what I'm after is a deeper understanding of how to do this matching to accurately detect more usages. (see link for kdoc explaining current algo.)

Screen Shot 2022-05-08 at 9 58 33 PM