在TeamCity上用kotlin编译android项目失败

我的构建步骤使用TeamCity模板中的gradle构建,但不幸的是我得到:

[16:29:22][:presentation:compileLocalDebugKotlin] Using kotlin incremental compilation [16:29:48][:presentation:compileLocalDebugKotlin] Compilation with Kotlin compile daemon was not successful [16:29:48][:presentation:compileLocalDebugKotlin] java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: [16:29:48][:presentation:compileLocalDebugKotlin] java.io.EOFException [16:29:48][:presentation:compileLocalDebugKotlin] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:229) [16:29:48][:presentation:compileLocalDebugKotlin] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162) 

任何想法,为什么我可能会得到这个?

我遇到了同样的问题。 不过,它并没有和Kotlin连接起来。

我必须禁用gradle deamon(不建议在CI服务器上)。

在teamcity中,您可以通过将-Dorg.gradle.daemon=false添加到GRADLE_OPTS环境变量来完成。

请参阅https://docs.gradle.org/current/userguide/gradle_daemon.html

默认情况下,Kotlin编译器在其自己的进程守护进程中执行。 在CI上运行时将此配置传递给Gradle以在相同的构建过程中编译Kotlin:

 -Dkotlin.compiler.execution.strategy="in-process" 

禁用Gradle守护进程在CI环境中也是常见的做法:

 -Dorg.gradle.daemon=false 

有人可能会认为Gradle守护进程属性也会禁用Kotlin编译器runner守护进程,但这不是目前发生的情况。 GradleKotlinCompilerRunner.kt仅考虑org.gradle.daemon属性之后kotlin.compiler.execution.strategy属性。 如果没有定义执行策略,跑步者默认使用"daemon"策略:

 val executionStrategy = System.getProperty(KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY) ?: DAEMON_EXECUTION_STRATEGY if (executionStrategy == DAEMON_EXECUTION_STRATEGY) { val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment) if (daemonExitCode != null) { return daemonExitCode } else { log.warn("Could not connect to kotlin daemon. Using fallback strategy.") } } val isGradleDaemonUsed = System.getProperty("org.gradle.daemon")?.let(String::toBoolean) return if (executionStrategy == IN_PROCESS_EXECUTION_STRATEGY || isGradleDaemonUsed == false) { compileInProcess(argsArray, compilerClassName, environment) } else { compileOutOfProcess(argsArray, compilerClassName, environment) } 

显式地将执行策略设置为"in-process"将使您得到compileInProcess()无论Gradle守护进程配置如何,但是,您可能需要禁用CI服务器上的两个守护进程。