Skip to main content

How to Find Which Dependency Adds a Specific Library or Class in Android Studio

How to Debug Which Dependency Adds a Specific Library or Class

Encountering a duplicate class error or an unexpected library in your Android project? A common culprit is a transitive dependency—a library that is automatically included by one of your direct dependencies. Thankfully, Gradle provides a powerful tool to investigate this: the dependency tree.

This guide will show you how to generate and read this tree to find the source of any problem library, like the common listenablefuture conflict.

The Quick Command

The simplest way to see your project's dependency hierarchy is to run a command in the terminal.

  1. Open the Terminal inside Android Studio (View > Tool Windows > Terminal).

  2. Run the following command:

bash

./gradlew app:dependencies
  • This will output the entire dependency tree for your app module to the terminal.

  • If your main module has a different name (e.g., myapp), replace app with that name:

    bash

./gradlew :myapp:dependencies

The Best Practice: Export to a File

The dependency tree can be very large and hard to read in the terminal. It's much more effective to export it to a text file for easy searching.

  1. In the terminal, navigate to your project's root folder (if you aren't already there).

  2. Run the command with a redirect to save the output to a file:

bash

./gradlew app:dependencies > deps.txt

This will create a file named deps.txt in your project's root directory.

How to Find the Problematic Dependency

Now that you have the deps.txt file, you can easily search for the problematic library or class.

  1. Open the deps.txt file in any text editor.

  2. Use the editor's Find function (Ctrl+F or Cmd+F).

  3. Search for the name of the jar or dependency causing the error.

    Example Searches:

    • For the common ListenableFuture conflict, search for: listenablefuture

    • For a duplicate class error, search for part of the class name or the jar file mentioned in the error message.

    • To find a specific library version, search for: guava or gson

  4. The search results will show you all occurrences. Look at the indentation in the tree to see the hierarchy.

Reading the Tree

Dependencies are displayed in a tree structure. A +--- indicates a direct dependency, and subsequent | and \--- symbols show transitive dependencies (libraries that your libraries depend on).

Example Output:
releaseRuntimeClasspath - Resolved configuration for runtime for variant: release
+--- com.example:some-library:1.2.3
|    \--- com.google.guava:listenablefuture:1.0
|         \--- ... (further dependencies)
\--- com.google.guava:guava:31.1-android

In this example, you can see that com.example:some-library:1.2.3 is pulling in the standalone listenablefuture:1.0 library, which could cause a conflict with the full guava library.

What to Do Next

Once you've identified which dependency is bringing in the problematic library, you can solve the conflict by:

  1. Excluding the Transitive Dependency: In your app/build.gradle file, you can exclude the specific module from the parent dependency.

  2. Aligning Versions: If different libraries require different versions of the same dependency, you can force a specific version using Gradle's dependency constraints.

By using the ./gradlew app:dependencies command, you turn a frustrating build error into a solvable mystery, giving you complete control over your project's dependencies.

 

You may also find below article helpful: 

Resolving "Duplicate Class ListenableFuture" Errors in Android Studio


Comments

Popular posts from this blog

How to set Profile Attribute in Siebel Workflow

For setting the Profile Attribute in Siebel Workflow, follow below steps: Add Business Service box in workflow. Open Business Service properties. Set  SessionAccessService in Business Service Name. Set  SetProfileAttr in Method Name. Then click on Business Service and set Input Arguments as below: Against Name argument you will add your profile attribute name and against Value argument you will add value for the new profile attribute, it could be from Process Property or Literal.

How to call Popup Applet through Server Script in Siebel

Background: Based on the requirements you need to show data or reports on a popup applet. You can invoke popup applet using workflow (below business service will be used in business service step), applet server script or browser script and using vanilla method and setting field user properties. Procedure: Below is the script for calling popup applet through server script: if (MethodName == "MethodName") { var oServiceAF = TheApplication().GetService("SLM Save List Service"); var inputPropAF = TheApplication().NewPropertySet(); var outputPropAF = TheApplication().NewPropertySet(); inputPropAF.SetProperty("Applet Name","ABC Popup Applet"); inputPropAF.SetProperty("Applet Mode","6"); inputPropAF.SetProperty("Applet Height", "700"); inputPropAF.SetProperty("Applet Width", "700"); oServiceAF.InvokeMethod("LoadPopupApplet", inputPropAF, outputPropAF) return (CancelOperati...

How to query or find record in Siebel Business Component

You can perform query operation on Business Component through Workflow, eScript with the help of Siebel Operation, Inbound E-mail Database Operations (method: FindRecord) or EAI Siebel Adapter (method: Query but you need to create Integration Objects). This Business Component can be Virtual Business Component (VBC), External Business Component (EBC) or generic Business Component (BC).  See also: Difference Between Business Components and How to Create BC in Siebel through Object Wizard through Workflow with the help of Siebel Operation Create a workflow and provide the Business Object, business component should be in this BO for which you want to perform the query operation. From the Palettes window drag drop the Siebel Operation into workflow designer plane. Select the Siebel Operation box and open the properties window, provide the Business Component name from the drop down list and set Query in Operation field. You can set the search specification by two means either provide the...