Search code examples
android-roomguava

Using Room-Guava in Android, cannot find ListenableFuture


I'm following this: https://developer.android.com/training/data-storage/room/async-queries

I'm trying to use ListenableFuture from Guava, so I included androidx.room:room-guava but Android Studio keeps complaining that "Cannot resolve symbol 'ListenableFuture'" and doesn't suggest any relevant import.

What is the correct import to include in Java source?

Here is my code:


build.gradle(:app)

...
// Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:2.4.3"

Java DAO interface

import androidx.room.Dao;
import androidx.room.Insert;

@Dao
public interface PressureMeasureDao
{
    @Insert
    public ListenableFuture<Integer> insertPressureMeasure(PressureMeasure pressureMeasure);
}

Solution

  • According to https://mvnrepository.com/artifact/androidx.room/room-guava/2.4.3 androidx.concurrent:concurrent-futures is a runtime dependency. Please check if https://mvnrepository.com/artifact/androidx.concurrent/concurrent-futures is present. ListenableFuture comes from its transitive dependency https://mvnrepository.com/artifact/com.google.guava/listenablefuture/1.0.