1

I've read and tried a lot of post solution for this problem but there is something I am doing wrong because it is not working for me.

I have just updated Android to AndroidX which came with the dependency androidx.preference:preference:1.1.0-alpha04. This dependency included the jar file named com.google.guava:listenablefuture:1.0@jar. The problem is that com.google.common.util.concurrent.ListenableFuture is found twice in the dependencies and this gives me an error when I build the project. I also found that the whole jar file (androidx.preference:preference:1.1.0-alpha04) can be removed as the file that is in there is already in another dependency library.

I have tried to add some notations to exclude the library but none of them worked out unfortunatelly. The jar file keeps being added once I build the project.

build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation('org.ros.android_core:android_10:[0.3, 0.4)') {
        exclude group: 'junit'
        exclude group: 'xml-apis'
    }
    // e.g. official msgs
    implementation 'org.ros.rosjava_messages:std_msgs:0.5.11'
    implementation 'org.ros.rosjava_messages:sensor_msgs:1.12.7'
    implementation 'org.ros.rosjava_messages:geometry_msgs:1.12.7'
    implementation 'org.ros.rosjava_bootstrap:message_generation:0.3.3'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha5'
    implementation ("androidx.preference:preference:1.1.0-alpha04", {
        exclude group: 'com.google.guava'
    })
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.27.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

repositories {
    mavenCentral()
}

The dependency that can be excluded:

enter image description here

What am I doing wrong or how should I actually exclude the jar file from the dependency?

EDIT: The reason I want to do this is because I get the following error:

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-12.0.jar (com.google.guava:guava:12.0) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)
Klyner
  • 3,983
  • 4
  • 26
  • 50
  • As per https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:excluding_transitive_module_dependencies, it should work like you already did. What's the output of `gradle dependencies`? – thokuest May 07 '19 at 13:47
  • What do you mean with what the output is? If I build my project, the dependency is still visible; that is what I can see. – Klyner May 07 '19 at 13:51
  • The source of truth is not the IDE. `gradle dependencies` is the command line to print the dependency graph. – thokuest May 07 '19 at 13:53
  • I think what you mean is `gradlew app:dependencies`. This outputs so much that not all content is visible in the terminal. Where should I look for and is there a way to output less or see all output? – Klyner May 07 '19 at 13:57
  • Depending on your OS/terminal, either configure the console buffer size or simply pipe the output to file, e.g. via `gradle dependencies > dependencies.txt`. – thokuest May 07 '19 at 14:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/192968/discussion-between-klyner-and-thokuest). – Klyner May 07 '19 at 14:11

1 Answers1

2

I think this should work:

implementation ("androidx.preference:preference:1.1.0-alpha04", {
    exclude group: 'com.google.guava'
})

EDIT

This answer probably should help you: https://stackoverflow.com/a/54717425/7947225

Add in your gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

In your build.gradle, add

configurations {
   all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}

Then Clean and finally Build the project.

Vince
  • 2,551
  • 1
  • 17
  • 22
  • Unfortunately it does not work. The jar is still in my dependency list. – Klyner May 07 '19 at 13:27
  • 1
    I advise you to run `gradlew app:dependencies` and find where `com.google.guava:listenablefuture` is used. I tried in my project and it's used several times. So I don't understand why you would remove this jar. – Vince May 07 '19 at 13:45
  • I edited the question with the reason why I want this to be excluded. – Klyner May 07 '19 at 13:54