Skip to main content

Resolving "Duplicate Class ListenableFuture" Errors in Android Studio

How to Fix the "Duplicate Class ListenableFuture" Error in Android

If you're working on an Android project and see a build error about a duplicate ListenableFuture class, you've encountered a common dependency conflict. This guide will explain why it happens and show you how to fix it.

Understanding the Error

The error message looks like this:

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules:
guava-23.0.jar (com.google.guava:guava:23.0)
and
listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0) 

This means two different libraries in your project are trying to provide the same class, causing a collision.

  • guava-23.0.jar contains the full Guava library, which includes ListenableFuture.

  • listenablefuture-1.0.jar is a standalone, minimal artifact containing only the ListenableFuture class.

The conflict arises when one of your dependencies requires the standalone JAR, but your project also includes the full Guava library.

The Solution: Exclude the Standalone Module

The most reliable fix is to identify which dependency is pulling in the standalone listenablefuture and exclude it.

Step 1: Find the Problematic Dependency

Open the terminal in Android Studio (View > Tool Windows > Terminal) and run this command to see your project's dependency tree:

For Groovy (build.gradle):

./gradlew :app:dependencies

 For Kotlin DSL (build.gradle.kts):

/gradlew :app:dependencies

(Note: If your main module has a name other than app, replace it in the command.)

Scan the output for com.google.guava:listenablefuture:1.0. This will show you which library is its parent.

Step 2: Exclude the Transitive Dependency

Once you've found the culprit, add an exclude rule to its dependency declaration in your app/build.gradle file.

Example in Kotlin DSL:

dependencies {
// ... other dependencies

implementation("com.example.someotherlibrary:core:1.2.3") {
exclude(group = "com.google.guava", module = "listenablefuture")
}

// Make sure you have a version of the full Guava library.
// Often, another Google library (like Firebase) will bring in a compatible
// Android version of Guava. If not, you might need to add it,
// or preferably, use constraints.
// Example: implementation("com.google.guava:guava:31.1-android")
}

Example in Groovy:

dependencies {
// ... other dependencies

implementation('com.example.someotherlibrary:core:1.2.3') {
exclude group: 'com.google.guava', module: 'listenablefuture'
}

// Make sure you have a version of the full Guava library.
// implementation 'com.google.guava:guava:31.1-android' // Example
}

Step 3: Sync, Clean, and Rebuild

  1. Sync your project with the Gradle files.

  2. Go to Build > Clean Project.

  3. Then, go to Build > Rebuild Project.

This should resolve the duplicate class error.

Additional Tips

  • Use Android-Compatible Guava: For Android projects, it's best to use the Android-specific version of Guava (e.g., com.google.guava:guava:31.1-android) to avoid compatibility issues and reduce method count.

  • Version Alignment: If you have multiple dependencies pulling in different versions of the full Guava library, you can force a specific version using a constraint:

dependencies {
constraints {
implementation("com.google.guava:guava:32.1.3-android") { // Use a recent Android-compatible version
because("Align Guava versions to avoid conflicts and ensure Android compatibility")
}
}
// ... your other dependencies
}
  • The Empty JAR: Some modern libraries depend on listenablefuture-9999.0-empty-to-avoid-conflict-with-guava, an intentionally empty artifact designed to prevent this exact conflict. If you see this, it's a sign of a well-designed dependency. Your conflict is likely from another library still using the old 1.0 artifact.

By following these steps, you can eliminate the build error and get your project running smoothly again.

You may also find below article helpful: 

How to Find Which Dependency Adds a Specific Library or Class 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...