63

I am trying to use WorkManager 1.0.0-alpha09. and getting this error:

Program type already present: 
com.google.common.util.concurrent.ListenableFuture

Message{kind=ERROR, text=Program type already present: 
com.google.common.util.concurrent.ListenableFuture, sources=[Unknown source 
file], tool name=Optional.of(D8)}

If i use version 1.0.0-alpha08 or less. I don't get this error, but i need public constructor

public Worker(Context context, WorkerParameters workerParams)
Simran Marok
  • 707
  • 1
  • 5
  • 9

4 Answers4

107

In my case, I had to add the following configurations to app's module build.gradle:

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

It happens because some dependencies use com.google.guava:guava and com.google.guava:listenablefuture together. It causes a dependency conflict.

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
40

Take a look at https://issuetracker.google.com/issues/116154359.

The workaround is:

implementation("android.arch.work:work-runtime:1.0.0-alpha09") {
    exclude group: 'com.google.guava', module: 'listenablefuture' 
}
Rahul
  • 19,744
  • 1
  • 25
  • 29
  • I am getting this error: **org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'**................................**Caused by: com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'** – Simran Marok Sep 28 '18 at 00:30
  • 1
    Try cleaning Android Studio's cache. Select 'File > Invalidate Caches / Restart' and then click the 'Invalidate and Restart' button. Clean and rebuild your project. – pfmaggi Sep 29 '18 at 11:02
  • @Rahul May I know, is there any side-effect of doing so? Will it pick a wrong version of listenablefuture library from other dependencies? – Cheok Yan Cheng Dec 27 '18 at 19:44
  • No, the interfaces are identical. There is no side-effect. – Rahul Dec 28 '18 at 20:16
20

I merely added implementation 'com.google.guava:guava:27.0.1-android' at the end of my app gradle file and the error went away.

user2297550
  • 3,142
  • 3
  • 28
  • 39
2

I am using ListenableFuture that comes from the work manager.

implementation("android.arch.work:work-runtime:1.0.0")

So excluding exclude group: 'com.google.guava', module: 'listenablefuture', didn't work for me.

I was using a dependency that internally used androidTestImplementation "com.google.truth:truth:42" that internally used com.google.guava:guava:25.0.1-android. This was causing the problem for me.

Upgrading com.google.truth:truth to 43 solved it for me.