skip to Main Content

My app suddenly doesn’t build anymore with this error:

error: package com.google.common.util.concurrent does not exist

import com.google.common.util.concurrent.ListenableFuture;

Why all of the sudden? This was working fine for quite some time. All libraries are up to date. What do I need to do for this to compile again?

Update: this is happening after upgrading

implementation 'com.google.android.gms:play-services-ads:22.3.0'

to

implementation 'com.google.android.gms:play-services-ads:22.4.0'

going back to version 22.3.0 and everything is fine. Is this a bug in the ads library? Some weird version mixup of different library versions, maybe with room or whatever?

2

Answers


  1. You could add an explicit dependency if you need ListenableFuture.

    https://developer.android.com/guide/background/asynchronous/listenablefuture

    dependencies {
        implementation "com.google.guava:guava:31.0.1-android"
    
        // To use CallbackToFutureAdapter
        implementation "androidx.concurrent:concurrent-futures:1.1.0"
    
        // Kotlin
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.6.0"
    }
    
    Login or Signup to reply.
  2. This seems to be intentional on Google’s part. I’ve taken a look at the maven repository page for the artifact for both the 22.3.0 version and 22.4.0, and the latter has a compile dependency on listenablefuture that is ’empty to avoid conflict with Guava`. It looks a little bit ambiguous so here is what the dependency says in its description (again, this dependency does NOT exist in 22.3.0):

    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 …

    This was taken from here ListenableFuture empty dependency.

    Ideally, if you want to use ListenableFuture, you would declare the Guava dependency but if you only need ListenableFuture, you may depend on the aforementioned artifact instead, as it seems to do the job. This is it:

    implementation("com.google.guava:listenablefuture:1.0")

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search