卡普gradle任务例外:类转换exception

执行任务’:app:kaptSomethingDebugKotlin’失败。

我已经重构了一些我的课程,我已经添加了一些kotlin类和function纯粹的类。

当我尝试编译项目,这些奇怪的事情发生,没有任何exception堆栈跟踪帮助我。

看来这个问题是由于Kotlin的java组合

Unable to receive command from client socket connection from /127.0.0.1:5573 to /127.0.0.1:13020. Discarding connection. org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:13020'. at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnectin.java:92) at org.gradle.launcher.daemon.server.SynchronizedDispatchConnection.receive(SynchronizedDispatchConnection.java:68) at org.gradle.launcher.daemon.server.DefaultDaemonConnection$1.run(DefaultDaemonConnection.java:63) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: Unexpected type tag 67 found. at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:142) at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36) at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:79) ... 8 more Unable to receive command from client socket connection from /127.0.0.1:5573 to /127.0 .0.1:13025. Discarding connection.org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:13025'. at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:92) at org.gradle.launcher.daemon.server.SynchronizedDispatchConnection.receive(SynchronizedDispatchConnection.java:68) at org.gradle.launcher.daemon.server.DefaultDaemonConnection$1.run(DefaultDaemonConnection.java:63) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: Unexpected type tag 67 found. at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:142) at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36) at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:79) ... 8 more Unable to receive command from client socket connection from /127.0.0.1:5573 to /127.0.0.1:13033. Discarding connection. org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:13033'. at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:92) at org.gradle.launcher.daemon.server.SynchronizedDispatchConnection.receive(SynchronizedDispatchConnection.java:68) at org.gradle.launcher.daemon.server.DefaultDaemonConnection$1.run(DefaultDaemonConnection.java:63) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: Unexpected type tag 67 found. at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:142) at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36) at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:79) ... 8 more Unable to receive command from client socket connection from /127.0.0.1:5573 to /127.0.0.1:13040. Discarding connection. org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:13040'. at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:92) at org.gradle.launcher.daemon.server.SynchronizedDispatchConnection.receive(SynchronizedDispatchConnection.java:68) at org.gradle.launcher.daemon.server.DefaultDaemonConnection$1.run(DefaultDaemonConnection.java:63) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: Unexpected type tag 67 found. at org.gradle.internal.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.read(DefaultSerializerRegistry.java:142) at org.gradle.internal.serialize.Serializers$StatefulSerializerAdapter$1.read(Serializers.java:36) at org.gradle.internal.remote.internal.inet.SocketConnection.receive(SocketConnection.java:79) ... 8 more e: java.lang.IllegalStateException: failed to analyze: java.lang.ClassCastException at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:137) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:386) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:96) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:892) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96) at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137) at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:919) at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:891) at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:385) at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Transport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassCastException 

One Solution collect form web for “卡普gradle任务例外:类转换exception”

经过一个星期的审判和失败,并逐条评论和取消注释,我意识到这是一个java编译器的bug,每次我写一个没有大括号的kotlin函数,这个exception被抛出

原因是我没有指定函数返回types,我的函数只有一个语句作为函数主体附加了一个等号。这种方式我们依靠kotlin来识别返回types的函数只声明。

当你将这一行语句放在大括号中并明确指定返回types时,exception就会消失

  • 打破或继续跨越阶级边界kotlin跳跃
  • 如何在Kotlin中使用Swagger @ApiResponses注解?
  • 什么时候Kotlin单例(用对象修饰符声明)实例化?
  • 使用LiveData和数据绑定
  • Varargs Kotlin Java互操作不正常
  • 如何在Android中使用Kotlin动态添加按钮
  • 如何在Kotlin中构建兼容的参数/结果类型的函数?
  • 如何声明参数作为函数没有返回值?
  • Kotlin中@BeforeAll的正确解决方法是什么?
  • ByteArray浮在kotlin
  • 运行时错误使用ListView Android与Kotlin?
  • Kotlin language will be the best programming language for Android.