I'm following this tutorial https://developer.android.com/guide/topics/search/appsearch#groovy
to make a sample app using AppSearch. However, when I get the schema part, I have unknown references on "Futures". I tried to look for any dependencies related to Futures concurrent for Android and I found 3 dependencies but it's not solving the unknown references to "Futures". I also don't know what should be "mExecutor" because I can't see the "Futures" class and its function because of the unknown reference.
Here is my my dependencies:
def appsearch_version = "1.0.0-alpha03"
implementation "androidx.concurrent:concurrent-listenablefuture-callback:1.0.0-beta01"
implementation "androidx.concurrent:concurrent-listenablefuture:1.0.0-beta01"
implementation "androidx.concurrent:concurrent-futures-ktx:1.1.0"
implementation "androidx.appsearch:appsearch:$appsearch_version"
// Use kapt instead of annotationProcessor if writing Kotlin classes
annotationProcessor "androidx.appsearch:appsearch-compiler:$appsearch_version"
implementation "androidx.appsearch:appsearch-local-storage:$appsearch_version"
// PlatformStorage is compatible with Android 12+ devices, and offers additional features
// to LocalStorage.
implementation "androidx.appsearch:appsearch-platform-storage:$appsearch_version"
Here is my code (the exact same as in the developer guide):
val sessionFuture = LocalStorage.createSearchSession(
LocalStorage.SearchContext.Builder(this, /*databaseName=*/"notes_app")
.build()
)
val setSchemaRequest = SetSchemaRequest.Builder().addDocumentClasses(Note::class.java)
.build()
val setSchemaFuture = Futures.transformAsync(//Futures unknown reference
sessionFuture,
{ session ->
session?.setSchema(setSchemaRequest)
}, mExecutor//?
)
val putRequest = PutDocumentsRequest.Builder().addDocuments(note).build()
val putFuture = Futures.transformAsync(
sessionFuture,
{ session ->
session?.put(putRequest)
}, mExecutor
)
Futures.addCallback(//Futures unknown reference
putFuture,
object : FutureCallback<AppSearchBatchResult<String, Void>?{//FutureCallback unknown reference
override fun onSuccess(result: AppSearchBatchResult<String, Void>?) {
// Gets map of successful results from Id to Void
val successfulResults = result?.successes
// Gets map of failed results from Id to AppSearchResult
val failedResults = result?.failures
}
override fun onFailure(t: Throwable) {
Log.e(TAG, "Failed to put documents.", t)
}
},
mExecutor//?
)
If you have any idea of the import I need to implement or any way to achieve the same thing with the kotlin coroutine ?
I know its very late for the answer. But, just in case if someone else is still searching for it, you will have to use Guava dependency