Android 找不到 com.google.common.util.concurrent.ListenableFuture 的 Studio class 文件

Android Studio class file for com.google.common.util.concurrent.ListenableFuture not found

我无法构建我的项目,因为它找不到 class。是不是我的sdk或者依赖有问题?

我试过使缓存失效并重新启动。我正在使用 api 29.

下面是出现错误的地方

public class PodcastUpdateWorker extends Worker {

}

这是错误打印输出

/home/snowman/AndroidStudioProjects/CorbettReportPodcasts/app/src/main/java/com/example/corbettreportpodcasts/PodcastUpdateWorker.java:36: error: cannot access ListenableFuture
public class PodcastUpdateWorker extends Worker {
       ^
  class file for com.google.common.util.concurrent.ListenableFuture not found

和我的家属

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.12.0'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.0'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.12.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
    implementation "androidx.room:room-runtime:2.2.5"
    annotationProcessor "androidx.room:room-compiler:2.2.5"
    testImplementation "androidx.room:room-testing:2.2.5"
    implementation 'androidx.work:work-runtime:2.4.0'
    implementation 'com.google.android.material:material:1.2.1'
}

感谢任何帮助

implementation "androidx.concurrent:concurrent-futures:1.1.0"

参考:https://developer.android.com/jetpack/androidx/releases/concurrent

检查 gradle 脚本(模块:应用程序)和 ...app>src>main>java.

中的包名称

将文件夹重命名为所需的程序包名称。确保所有 java 文件中的包名称也已更改。重命名后,将您的项目与 gradle 个文件同步。

如果您在第一次 Gradle 同步后执行此操作,则此技巧可能无效。您需要手动更改它们。

exoplayer 库存在与 listenablefuture 冲突导致找不到的问题。 READ MORE

你可以包含 guava implementation 'com.google.guava:guava:29.0-android' 来解决这个问题

我更新解决了

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 
to 
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

也将这些更新到最新版本(如果适用)

api 'androidx.core:core-ktx:1.3.2' 
api "org.jetbrains.kotlin:kotlin-stdlib:1.4.32"