Android:compileDebugKotlin 失败并出现 java.lang.ClassCastException

标签 android kotlin gradle android-jetpack-compose

我在构建 Android 项目时遇到了一个奇怪的问题。 compileDebugKotlin 任务失败并出现 java.lang.ClassCastException,它引用了一些内部 kotlin 类。我也无法确定到底是什么导致了这个问题。我不知道如何处理此类问题。我唯一想到的是可能存在一些矛盾的 gradle 依赖关系。但应用程序模块 build.gradle 文件中的所有依赖项都是最新的,并且对我的项目至关重要。如果您知道如何解决此问题,请发表评论。

java.lang.ClassCastException: class org.jetbrains.kotlin.psi.KtSuperTypeCallEntry cannot be cast to class org.jetbrains.kotlin.psi.KtCallExpression (org.jetbrains.kotlin.psi.KtSuperTypeCallEntry and org.jetbrains.kotlin.psi.KtCallExpression are in unnamed module of loader 'app')
    at androidx.compose.compiler.plugins.kotlin.ComposeDiagnosticSuppressor.isSuppressed(ComposeDiagnosticSuppressor.kt:64)
    at org.jetbrains.kotlin.resolve.diagnostics.BindingContextSuppressCache.isSuppressedByExtension(KotlinSuppressCache.kt:241)
    at org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache.isSuppressed(KotlinSuppressCache.kt:69)
    at org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache.access$isSuppressed(KotlinSuppressCache.kt:43)
    at org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache$filter$1.invoke(KotlinSuppressCache.kt:50)
    at org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache$filter$1.invoke(KotlinSuppressCache.kt:49)
    at kotlin.collections.CollectionsKt___CollectionsKt.filter(_Collections.kt:3557)
    at org.jetbrains.kotlin.resolve.diagnostics.DiagnosticsWithSuppression.all(DiagnosticsWithSuppression.java:57)
    at org.jetbrains.kotlin.resolve.diagnostics.MutableDiagnosticsWithSuppression.all(MutableDiagnosticsWithSuppression.kt:47)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport$Companion.reportDiagnostics(AnalyzerWithCompilerReport.kt:157)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport$Companion.reportDiagnostics(AnalyzerWithCompilerReport.kt:165)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:120)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:253)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:100)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:170)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:434)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:120)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:357)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:299)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl$rebuild(IncrementalCompilerRunner.kt:118)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:169)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:80)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:622)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:100)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1713)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

我的 gradle 依赖项:

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.google.android.play:core:1.10.2'
    //implementation 'com.google.code.gson:gson:2.8.6'

    // Compose
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation "androidx.compose.foundation:foundation:$compose_version"
    implementation "androidx.compose.foundation:foundation-layout:$compose_version"
    implementation 'androidx.activity:activity-compose:1.4.0'
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.6.10"
    // Material Design
    implementation "androidx.compose.material:material:$compose_version"
    // Integration with ViewModels
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.0'
    implementation "androidx.navigation:navigation-compose:2.4.0-rc01"
    implementation 'androidx.navigation:navigation-runtime-ktx:2.4.0-rc01'
    implementation "androidx.compose.animation:animation:$compose_version"
    // Coil for Jetpack Compose
    implementation "io.coil-kt:coil-compose:1.3.0"
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
    // Material Icons
    implementation 'androidx.compose.material:material-icons-core:1.0.5'
    implementation 'androidx.compose.material:material-icons-extended:1.0.5'

enter image description here

最佳答案

就我而言,当我添加调用 java 类的命名参数时,我得到了相同的堆栈跟踪。没有 IDE 警告,堆栈跟踪也没有指向它。撤消命名参数不再给我这个错误。

关于Android:compileDebugKotlin 失败并出现 java.lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70668376/

相关文章:

android - 错误:无法解析 ':app@debug/compileClasspath'的依赖项:无法下载okhttp.jar(com.squareup.okhttp3:okhttp:4.3.1)

java - 我怎样才能让喊播流几乎立即开始播放

java - 使用 BufferedReader 从文本文件中的特定行获取数据

android - Cordova 应用程序未在 Android 上调用 API - net::ERR_CONNECTION_REFUSED

kotlin - IntelliJ在新的Ktor项目中缺少对slf4j的引用

android - 在 gradle 构建期间更新 README.md 中的版本号

android - 如果使用Google Play服务,则不能在没有版本冲突的情况下使用最新的compileSdkVersion和targetSdkVersion

android - Android 中带有页面 curl 的 Pdf 查看器库

regex - 用regexp替换yaml结构中的版本

algorithm - 使用 A* 搜索算法解决Theseus 和 Minotaur 谜题