PAYATHON 2026

Chaquopy 17 在 Gradle 9.7.1 下配置缓存报错如何解决

数据小陈

结论:先把 Gradle 的 configuration cache 关掉,再重新构建。你遇到的 Starting an external process ... during configuration time is unsupported 和 error writing value of type 'kotlin.SynchronizedLazyImpl' 是 Chaquopy 17.0.0 插件和 Gradle 9.7.1 的配置缓存不兼容造成的。你的 Python 代码没有问题,也不用改 Chaquopy 的 buildPath。multi-string notation 警告来自插件内部的依赖声明,Gradle 9 还能通过,Gradle 10 会报错。一般只能等 Chaquopy 升级,或者换用兼容的 Gradle 版本。

先关闭 configuration cache

在项目根目录的 gradle.properties 里加一行:

org.gradle.configuration-cache=false

命令行构建时也可以显式关闭:

./gradlew --stop
./gradlew clean assembleDebug --no-configuration-cache

Android Studio 里如果勾了 Configuration cache,也在 Gradle 设置里取消。关掉后重新 Sync 再 Run。这里关的是 configuration cache,build cache 不用动。

检查 Chaquopy 插件和 Python 构建解释器

根 build.gradle.kts 保留版本声明,app 模块只应用插件,不要重复写版本:

// 根 build.gradle.kts
plugins {
    alias(libs.plugins.android.application) apply false
    id("com.chaquo.python") version "17.0.0" apply false
}
// app/build.gradle.kts
plugins {
    alias(libs.plugins.android.application)
    id("com.chaquo.python")
}

如果系统默认 python3 不可用,或日志里 Chaquopy 检查的版本与系统解释器不一致,再在 app 模块指定构建用 Python:

android {
    defaultConfig {
        python {
            buildPython("/usr/bin/python3.10") // 按你机器上实际可用的解释器修改
        }
    }
}

先执行 python3 --version 和 /usr/bin/python3.10 --version 确认路径存在。日志中 Chaquopy 检查的是 3.10,所以让 buildPython 指向可用的 3.10 解释器更稳。具体支持范围以 Chaquopy 17.0.0 的要求为准。不要为了绕这个错误手写 Gradle task 来构建 Python,也不建议改 buildPath,这些做法容易继续在配置阶段启动外部进程。

版本兼容性

Gradle 9.7.1 和 API 37.1 都比较新,Chaquopy 17.0.0 未必完整适配。关闭 configuration cache 后如果仍然失败,优先尝试 Chaquopy 官方支持的 Gradle/AGP 组合,或者升级到已修复配置缓存兼容性的 Chaquopy 版本。multi-string notation 警告不要靠改用户依赖来消除,等插件更新即可。如果必须上 Gradle 10,先确认 Chaquopy 已经支持。

注意事项

  • 清理配置缓存报告和旧缓存后再试:./gradlew clean。必要时删除项目下的 .gradle/configuration-cache。
  • configuration-cache 和 build-cache 不是一回事,不要把 org.gradle.caching 关了。
  • 如果指定 buildPython 后报路径或版本错误,先解决解释器问题,不要继续改 buildPath。
  • 如果关闭 configuration cache 后能运行,说明问题就在插件兼容性。等 Chaquopy 修复后再重新开启。

备注:内容仅供参考。