Gradle:“无法缓存配置缓存状态”

Zae*_*eem 18 android android-studio

Configuration cache state could not be cached: field 'actions' from type 'org.gradle.api.DefaultTask': error writing value of type 'java.util.ArrayList'
> Configuration cache state could not be cached: field 'closure' from type 'org.gradle.api.internal.AbstractTask$ClosureTaskAction': error writing value of type 'com.chaquo.python.PythonPlugin$_createAssetsTasks_closure21$_closure46'
   > Configuration cache state could not be cached: field 'variant' from type 'com.chaquo.python.PythonPlugin$_createAssetsTasks_closure21$_closure46': error writing value of type 'groovy.lang.Reference'
      > Configuration cache state could not be cached: field 'value' from type 'groovy.lang.Reference': error writing value of type 'com.android.build.gradle.internal.api.ApplicationVariantImpl'
         > Configuration cache state could not be cached: field 'testVariant' from type 'com.android.build.gradle.internal.api.ApplicationVariantImpl': error writing value of type 'com.android.build.gradle.internal.api.TestVariantImpl'
            > Configuration cache state could not be cached: field 'variantData' from type 'com.android.build.gradle.internal.api.TestVariantImpl': error writing value of type 'com.android.build.gradle.internal.variant.TestVariantData'
               > Configuration cache state could not be cached: field 'testedVariantData' from type 'com.android.build.gradle.internal.variant.TestVariantData': error writing value of type 'com.android.build.gradle.internal.variant.ApplicationVariantData'
                  > Configuration cache state could not be cached: field 'artifacts' from type 'com.android.build.gradle.internal.variant.ApplicationVariantData': error writing value of type 'com.android.build.api.artifact.impl.ArtifactsImpl'
                     > Configuration cache state could not be cached: field 'storageProvider' from type 'com.android.build.api.artifact.impl.ArtifactsImpl': error writing value of type 'com.android.build.api.artifact.impl.StorageProviderImpl'
                        > Configuration cache state could not be cached: field 'fileStorage' from type 'com.android.build.api.artifact.impl.StorageProviderImpl': error writing value of type 'com.android.build.api.artifact.impl.TypedStorageProvider'
                           > Configuration cache state could not be cached: field 'singleStorage' from type 'com.android.build.api.artifact.impl.TypedStorageProvider': error writing value of type 'java.util.LinkedHashMap'
                              > java.util.ConcurrentModificationException (no error message)
Run Code Online (Sandbox Code Playgroud)

这是我在与 gradle 同步时收到的错误消息,请帮我解决这个问题

Zae*_*eem 40

文件中gradle.properties有一行代码org.gradle.unsafe.configuration-cache=true 删除它并重建项目,就可以解决问题。

这是由于 Gradle 的配置缓存造成的。有些库不可缓存,因此会出现错误。


Gak*_*ket 13

虽然上面的答案在技术上是正确的,但它只是隐藏了问题而不是正确解决问题。

Gradle 团队提出了一个非常酷的功能,有助于在“配置”阶段节省几十秒甚至几分钟的时间。配置缓存类似于构建缓存,但用于...配置步骤。有时他们需要一段时间。

因此,关闭它是有效的,但会增加构建时间。当您没有更改构建文件而仅更改了实际代码时,每次都可以使用配置缓存。你知道吗?我们公司95%的情况都是这样。因此,通过启用它,我们可以在每次构建时节省 1-2 分钟。

如何?这需要一些工作。幸运的是,Gradle 人员写了一个很好的分步说明。因此,如果您有一些时间来完成技术任务,我绝对建议您尝试为所有或至少部分任务配置这个东西: Gradle 配置缓存指令