Mac下Android Studio编译Kotlin项目遇NoSuchFileException错误求助
解决Android Studio编译Kotlin时找不到.salive文件的问题
问题描述
Mac系统下使用Android Studio构建项目,compileReleaseKotlin任务执行失败,报错java.nio.file.NoSuchFileException,提示找不到/Users/jianpingliang/MyApplication/build/kotlin/sessions/目录下的.salive文件,重装Kotlin后问题依旧。
错误日志如下:
FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':IAP:compileReleaseKotlin'. > java.nio.file.NoSuchFileException: /Users/jianpingliang/MyApplication/build/kotlin/sessions/kotlin-compiler-8513955117543825844.salive * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':Only:compileReleaseKotlin'. > java.nio.file.NoSuchFileException: /Users/jianpingliang/MyApplication/build/kotlin/sessions/kotlin-compiler-4081466192223101837.salive * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/8.0-milestone-3/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 779ms 60 actionable tasks: 4 executed, 56 up-to-date
解决方案
清理项目构建缓存
- 在Android Studio中点击菜单栏
Build->Clean Project,清理完成后重新构建。 - 若Clean无效,手动删除项目根目录下的
build文件夹,以及用户目录下的~/.gradle/caches目录,重启Android Studio后重新构建。
- 在Android Studio中点击菜单栏
禁用Kotlin编译会话缓存
在项目根目录的gradle.properties文件中添加以下配置,强制关闭Kotlin编译会话缓存:kotlin.compiler.execution.strategy=in-process同步Gradle后尝试构建项目。
检查Gradle与Kotlin版本兼容性
确保项目使用的Gradle版本和Kotlin插件版本匹配,建议在项目根目录的build.gradle(Project级)中使用官方推荐的版本组合,例如:plugins { id 'com.android.application' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false id 'org.jetbrains.kotlin.android' version '1.8.20' apply false }同步Gradle后重新构建。
重置Android Studio配置
关闭Android Studio,删除以下目录后重启(替换<版本号>为你的Android Studio版本,如2022.3.1):~/Library/Application Support/Google/AndroidStudio<版本号>~/Library/Caches/Google/AndroidStudio<版本号>
内容的提问来源于stack exchange,提问作者Albert Ping
相关产品推荐
相关产品推荐

