Android 工作室找不到 class wearos 瓷砖的期货
Android studio cannot find class Futures for wearos tiles
我的意图是为 wearos 创建磁贴。我遇到的问题是找不到此“Futures”所需的 class。它应该位于 com.google.common.util.concurrent.Futures 但 android studio 找不到它。
我的构建错误状态如下:
/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
这导致了一个明显的事实,即我不能在我的代码中使用这个 class,所以我的其余错误只说“找不到符号 method/variable 期货”。
我的build.gradle如下:
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()
);
}
}
我该如何解决这个问题?
期货可以在这里找到:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.1'
番石榴期货住在这里
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation("com.google.guava:guava:31.0.1-android")
kotlinx-coroutines-guava 恰好依赖于它,所以如果你也想要协程,请使用它。
我的意图是为 wearos 创建磁贴。我遇到的问题是找不到此“Futures”所需的 class。它应该位于 com.google.common.util.concurrent.Futures 但 android studio 找不到它。
我的构建错误状态如下:
/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
这导致了一个明显的事实,即我不能在我的代码中使用这个 class,所以我的其余错误只说“找不到符号 method/variable 期货”。
我的build.gradle如下:
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()
);
}
}
我该如何解决这个问题?
期货可以在这里找到:
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.1'
番石榴期货住在这里
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation("com.google.guava:guava:31.0.1-android")
kotlinx-coroutines-guava 恰好依赖于它,所以如果你也想要协程,请使用它。