'How to determine and delete unused dependencies in Android Studio safely?

IDE: Android Studio Bumblebee 2021.1.1

I see a lot of dependencies in my project (project structure -> dependencies -> all modules) which are not added via build.gradle (module).

How can I verify that these are not used somewhere indirectly and how to delete them safely?

In .idea\libraries I see the relevant xml file but don't find any sources or binaries which are listed there. I don't see any mention mention of most of the libraries in the source code either.

Is it safe to just delete the so obviously non used xml files in the .idea\libraries folder for which I don't find any mention in the source code?


E.G. .idea/libraries/Gradle__com_ximpleware_vtd_xml_2_11.xml

<component name="libraryTable">
  <library name="Gradle: com.ximpleware:vtd-xml:2.11">
    <CLASSES>
      <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd-xml-2.11.jar!/" />
    </CLASSES>
    <JAVADOC>
      <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/18a5f2a50ab41af03763fd215d14e620b12c7055/vtd-xml-2.11-javadoc.jar!/" />
    </JAVADOC>
    <SOURCES>
      <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/fa2dcbbe7f3bf99312efc0a010d8aa97f0f5779e/vtd-xml-2.11-sources.jar!/" />
    </SOURCES>
  </library>
</component>

I'll try to run a test once I have more time but it's obviously impossible to run all test paths to be absolutely sure.



Solution 1:[1]

I see a lot of dependencies in my project (project structure -> dependencies -> all modules) which are not added via build.gradle (module).

Those are transitive dependencies. The dependencies that you list in build.gradle themselves have other dependencies that get included in your app.

How can I verify that these are not used somewhere indirectly

They are all used somewhere indirectly.

Is it safe to just delete the so obviously non used xml files in the .idea\libraries folder for which I don't find any mention in the source code?

Probably not. I imagine that they will get re-generated if needed. I recommend leaving them alone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CommonsWare