Hector
Hector

Reputation: 5438

How to resolve Program type already present: com.google.common.util.concurrent.ListenableFuture?

My current Android project will now not build due the following error

AGPBI: {"kind":"error","text":"Program type already present: com.google.common.util.concurrent.ListenableFuture","sources":[{}],"tool":"D8"}
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/....
Program type already present: com.google.common.util.concurrent.ListenableFuture

I am using Android studio version

Android Studio 3.2
Build #AI-181.5540.7.32.5014246, built on September 17, 2018
JRE: 1.8.0_152-release-1136-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

The following link is Less than helpful

Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

The changes I made to trigger this error were as follows:-

Increase my tarke sdk version et.c from 27 to 28

   compileSdkVersion = 28
   targetSdkVersion = 28
   minSdkVersion = 21
   buildToolsVersion = "28.0.2"
   supportLibVersion = "28.0.0"

increase my kotlin version to ext.kotlin_version = '1.2.61'

and switch to gradle 3.2.0

 classpath 'com.android.tools.build:gradle:3.2.0'

How can I fix my gradle build?

UPDATE

Having run ./gradlew app:dependencies

I discovered this

+--- android.arch.work:work-runtime:1.0.0-alpha09
|    +--- android.arch.lifecycle:extensions:1.1.0 -> 1.1.1 (*)
|    +--- androidx.concurrent:futures:1.0.0-alpha01
|    |    +--- com.google.guava:listenablefuture:1.0
|    |    \--- androidx.annotation:annotation:1.0.0-rc01
|    \--- android.arch.persistence.room:runtime:1.1.1-rc1
|         +--- android.arch.persistence.room:common:1.1.1-rc1
|         |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         +--- android.arch.persistence:db-framework:1.1.1-rc1
|         |    +--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         |    \--- android.arch.persistence:db:1.1.1-rc1
|         |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         +--- android.arch.persistence:db:1.1.1-rc1 (*)
|         +--- android.arch.core:runtime:1.1.1 (*)
|         \--- com.android.support:support-core-utils:26.1.0 -> 28.0.0 (*)

I therefore added

api ("android.arch.work:work-runtime:$archWorkerRuntimeVersion") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

to my gradle build

this caused

More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'

Therefore I added

packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }

and now my build completes OK

Does it really have to be this hard to increase Android versions?

Upvotes: 8

Views: 4380

Answers (0)

Related Questions