我的意图是为wearos创建瓷砖。我遇到的问题是,这个所需的类,";Futures";,找不到。它应该位于com.google.common.util.courrent.Futures中,但android工作室在那里找不到它。
我的构建错误状态如下:
/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
这导致了一个明显的事实,即我不能在代码中使用这个类,所以我的其余错误只说";找不到符号方法/变量Futures";。
我的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协同程序番石榴恰好依赖于它,所以如果你也想要协同程序,请使用它。