Android Question Class Defined multiple times (SOLVED)

walterf25

Expert
Licensed User
Longtime User
Hi All, I am working on a proof of concept, I am wrapping a library that requires of a few other dependencies listed below.
I am seeing this error when trying to compile the app.
Error in C:\Android_SDK2\tools\..\extras\b4a_local\unpacked-guava-27.0.1-android-63860924590363\dex_v1\guava-27.0.1-android.zip:classes.dex:
Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: C:\Android_SDK2\tools\..\extras\b4a_local\unpacked-guava-27.0.1-android-63860924590363\dex_v1\guava-27.0.1-android.zip:classes.dex, C:\Android_SDK2\tools\..\extras\b4a_local\unpacked-com.google.guava-listenablefuture-63860287776000\dex_v1\com.google.guava-listenablefuture.zip:classes.dex
Compilation failed

The dependency that is causing this issue is guava-27.0.1-android.jar which obviously is required by the library I am wrapping, I created a small example in Android Studio using the Main library I am trying to wrap, and I see that there's an empty jar file that is being used to prevent this very same issue I am seeing now with B4A.

As you can see from this screen shot in my Android Studio project where the dependencies are loaded.
1725512003671.png


The listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar is generated to avoid conflict with the guava library.

Inside this empty jar file, there is a pom.xml file that contains this description/explanation in it
An empty artifact that Guava depends on to signal that it is providing
ListenableFuture -- but is also available in a second "version" that
contains com.google.common.util.concurrent.ListenableFuture class, without
any other Guava classes. The idea is:

- If users want only ListenableFuture, they depend on listenablefuture-1.0.

- If users want all of Guava, they depend on guava, which, as of Guava
27.0, depends on
listenablefuture-9999.0-empty-to-avoid-conflict-with-guava. The 9999.0-...
version number is enough for some build systems (notably, Gradle) to select
that empty artifact over the "real" listenablefuture-1.0 -- avoiding a
conflict with the copy of ListenableFuture in guava itself. If users are
using an older version of Guava or a build system other than Gradle, they
may see class conflicts. If so, they can solve them by manually excluding
the listenablefuture artifact or manually forcing their build systems to
use 9999.0-....

Is there any way to do the same with B4A, I tried adding the listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar with #AdditionalJar directive but I still get the same error as above.

Thanks guys, normally when wrapping libraries, I almost never have any issues such as this, any help or suggestions will be appreciated.

FYI, I already checked all the other library dependencies and I don't see the class that is causing the issue
com.google.common.util.concurrent.ListenableFuture
anywhere else, so I'm not sure how I can exclude this class or if even possible.

Walter
 

walterf25

Expert
Licensed User
Longtime User
Add this to main module:
B4X:
#ExcludedLib: guava-27.0.1-android.jar
#AdditionalJar: com.google.guava:guava
#AdditionalJar: com.google.guava:listenablefuture

Assuming that it works then you can update the @DependsOn list with these two components.
Thanks Erel, that works like a charm, one way I had figured out was to rename the guava jar file to a zip file, unzipped that file and delete the class that was being detected as duplicate.

I like your approach better.

Thanks,
Walter
 
Upvote 0
Top