我无法构建我的项目,因为它失败了,因为它找不到类。我的 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'
}
如有任何帮助,我们将不胜感激
exoplayer 库存在与可监听未来冲突的问题,导致找不到它。 了解更多
你可以加入番石榴
implementation 'com.google.guava:guava:29.0-android'
来解决这个问题
implementation "androidx.concurrent:concurrent-futures:1.1.0"
参考:https://developer.android.com/jetpack/androidx/releases/concurrent
检查 gradle 脚本 (module:app) 和
...app>src>main>java
中的包名称。
将文件夹重命名为所需的包名称。确保所有 java 文件中的包名称也已更改。重命名后,将项目与 gradle 文件同步。
如果您在第一次 Gradle 同步后执行此操作,则此技巧可能不起作用。您需要手动更改它们。
我通过更新解决了这个问题
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"
我只是在 gradle-wrapper.properties 中更改了这一行: distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zip 到 distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
除了已接受的答案之外。我没有在应用程序中使用 Exoplayer。深入挖掘后,我发现如果你使用 Google 的番石榴库来解决这样的冲突:
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
这也会引起一个问题。删除这个依赖关系解决了这个问题。但另一方面,如果您使用某些库,则会导致
listenablefeature
出现问题,相反添加此依赖项可以解决问题。