Android Studio的类文件未找到:com.google.common.util.concurrent.ListenableFuture。

huangapple go评论77阅读模式
英文:

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

问题

以下是翻译好的内容:

无法构建我的项目,因为它在构建过程中失败,无法找到一个类。我的 SDK 或依赖关系是否有问题?

我尝试过清除缓存并重新启动。我正在使用 API 29。

以下是错误显示的位置:

public class PodcastUpdateWorker extends Worker {

}

以下是错误信息的输出:

/home/snowman/AndroidStudioProjects/CorbettReportPodcasts/app/src/main/java/com/example/corbettreportpodcasts/PodcastUpdateWorker.java:36: 错误: 无法访问 ListenableFuture
public class PodcastUpdateWorker extends Worker {
       ^
  找不到 com.google.common.util.concurrent.ListenableFuture 的类文件

以及我的依赖项:

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'
}

非常感谢您的帮助。

英文:

I cannot build my project due to it failing because it cannot find a class. Is there something wrong with my sdk or dependancies?

I have tried invalidating cache and restarting. I am using api 29.

The following is where the error shows up

public class PodcastUpdateWorker extends Worker {

}

Here is the error printout

/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

and my dependancies

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'
}

any help is appreciated

答案1

得分: 27

有一个问题与exoplayer库冲突,导致无法找到它。了解更多

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

英文:

There is an issue with the exoplayer library conflicting with listenablefuture causing it not to be found. READ MORE

you can include guava implementation 'com.google.guava:guava:29.0-android' to fix this

答案2

得分: 6

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

Reference: https://developer.android.com/jetpack/androidx/releases/concurrent

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

Reference: https://developer.android.com/jetpack/androidx/releases/concurrent

答案3

得分: 0

检查 gradle 脚本(module:app)和 ...app > src > main > java 中的软件包名称。

将文件夹的名称更改为所需的软件包名称。确保还要在所有 Java 文件中更改软件包名称。重命名后,请与 gradle 文件同步您的项目。

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

英文:

Check for the package name in gradle scripts (module:app) and in ...app>src>main>java.

Rename the folder to the desired package name. Make sure that the package name is changed in all the java files also. After renaming, sync your project with gradle files.

If you are doing this after the first Gradle sync, then this trick may not work. You need to change them manually.

答案4

得分: 0

我通过更新以下内容来解决这个问题:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

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

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"
英文:

I solved it by updating

 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"

also update these to latest versions, if applicable

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

答案5

得分: -1

除了被接受的答案之外。我在应用程序中没有使用Exoplayer。经过更深入的挖掘,我发现如果你使用谷歌的guava库来解决类似这样的冲突:

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

这也会导致问题。移除这个依赖项解决了问题。但另一方面,如果你使用了某个库,它引起了与listenablefeature相关的问题,相反地,添加这个依赖项会解决问题。

英文:

In addition to the accepted answer. I didn't user Exoplayer in the application. After digging deeper I found that if you use Google's library for guava to fix conflicts like this:

implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

This will also cause an issue. Removing this dependency solved the problem. BUT on the other hand, if you use some library, which causes the problem with listenablefeature in opposite adding this dependency solves the problem.

huangapple
  • 本文由 发表于 2020年10月10日 13:02:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64290141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定