5

An AAR library already uses com.google.guava.

If an app includes the following in its build.gradle:

api 'com.google.guava:guava:27.0-android'

Building the app generates the following error:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: com.google.common.util.concurrent.internal.InternalFutures

If I do not include "api 'com.google.guava:guava:27.0-android'", the app can be built, but it has runtime error of java.lang.NoClassDefFoundError when it reaches the point of using the Guava method: Iterables.find

Hong
  • 17,643
  • 21
  • 81
  • 142

2 Answers2

10

I had to update to version 27.0.1, at the time of writing they still haven't updated the README with this new version.

implementation 'com.google.guava:guava:27.0.1-android'
Adam
  • 2,167
  • 5
  • 19
  • 33
5

Since Guava 27.0, ListenableFuture is located in separate artifact, see the announcement. You can try two things (one at a time):

  1. Exclude "listenablefuture" module (group "com.google.guava") and build your project again.
  2. I don't know the AAR specifics, but it could be that 27.0-android doesn't work with AAR, so you should try 26.0-android instead.
Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
  • 1
    Thank you! The library is our own library that uses api 'com.google.guava:guava:27.0-android'. The problem started when I updated Guava from 23.5-android to 27.0-android. If I use 23.5-android in the app (the library still uses 27.0-android), the app will work. Following your answer, the following in the app also works: compile('com.google.guava:guava:27.0-android'){ exclude group: "com.google.guava" }. This is strange because I thought the above essentially excludes the entire Guava package. – Hong Oct 25 '18 at 10:43