Issue
My intentions is to create tiles for wearos. The problem I get is that the class needed for this, "Futures", is not found. It should be located in com.google.common.util.concurrent.Futures but android studio cannot find it there.
My build error states as follows:
/home/user/AndroidStudioProjects/yyy/app/src/main/java/com/xxx/yyy/services/TileService.java:13: error: cannot find symbol
import com.google.common.util.concurrent.Futures;
^
symbol: class Futures
location: package com.google.common.util.concurrent
This leads to the obvious fact that I cannot use this class in my code so the rest of my errors only say "cannot find symbol method/variable Futures".
My build.gradle is as follows:
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.xxx.yyy"
minSdk 28
targetSdk 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.wear:wear:1.2.0'
/* for tiling: */
// Use to implement support for wear tiles
implementation 'androidx.wear.tiles:tiles:1.0.0'
implementation "androidx.concurrent:concurrent-futures:1.1.0"
// Use to preview wear tiles in our own app
debugImplementation 'androidx.wear.tiles:tiles-renderer:1.0.0'
// Use to fetch tiles from a tile provider in our tests
testImplementation 'androidx.wear.tiles:tiles-testing:1.0.0'
}
TileService.java:
package com.elvigo.spotprice.services;
import androidx.annotation.NonNull;
import androidx.wear.tiles.LayoutElementBuilders.Text;
import androidx.wear.tiles.LayoutElementBuilders.Layout;
import androidx.wear.tiles.RequestBuilders;
import androidx.wear.tiles.ResourceBuilders;
import androidx.wear.tiles.TileBuilders.*;
import androidx.wear.tiles.TimelineBuilders.TimelineEntry;
import androidx.wear.tiles.TimelineBuilders.Timeline;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Futures; // <-- Error here
public class TileService extends androidx.wear.tiles.TileService {
private static final String RESOURCES_VERSION = "1";
@NonNull
@Override
protected ListenableFuture<Tile> onTileRequest(
@NonNull RequestBuilders.TileRequest requestParams
) {
return Futures(new Tile.Builder()
.setResourcesVersion(RESOURCES_VERSION)
.setTimeline(new Timeline.Builder()
.addTimelineEntry(new TimelineEntry.Builder()
.setLayout(new Layout.Builder()
.setRoot(new Text.Builder()
.setText("Hello world!").build()
).build()
).build()
).build()
).build()
).build();
}
@NonNull
@Override
protected ListenableFuture<ResourceBuilders.Resources> onResourcesRequest(
@NonNull RequestBuilders.ResourcesRequest requestParams
) {
return Futures.immediateFuture(new ResourceBuilders.Resources.Builder()
.setVersion(RESOURCES_VERSION)
.build()
);
}
}
How do I resolve this?
Solution
Guava futures lives here
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation("com.google.guava:guava:31.0.1-android")
kotlinx-coroutines-guava happens to depend on it, so use that if you also want coroutines.
Answered By - Yuri Schimke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.