ITmob-Ly
发布于 2024-09-11 / 447 阅读
0

Android Exception - UncheckedIOException: Could not read workspace metadata from metadata.bin

异常信息

在 Android 项目中,修改 Gradle 相关的文件后重新同步项目时,同步失败,输出如下错误信息:

Starting Gradle Daemon...
Gradle Daemon started in 1 s 459 ms

FAILURE: Build failed with an exception.

* What went wrong:
A build operation failed.
    Could not read workspace metadata from C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin
> Could not read workspace metadata from C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin

* Try:
> 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.

* Exception is:
org.gradle.internal.operations.MultipleBuildOperationFailures: A build operation failed.
    Could not read workspace metadata from C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin
	at org.gradle.internal.operations.DefaultBuildOperationQueue.markFinished(DefaultBuildOperationQueue.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationQueue.waitForWorkToComplete(DefaultBuildOperationQueue.java:128)
	at org.gradle.internal.operations.DefaultBuildOperationQueue.waitForCompletion(DefaultBuildOperationQueue.java:107)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.executeInParallel(DefaultBuildOperationExecutor.java:106)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.runAll(DefaultBuildOperationExecutor.java:65)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ParallelResolveArtifactSet$VisitingSet.visit(ParallelResolveArtifactSet.java:66)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSetResolver$1.run(ResolvedArtifactSetResolver.java:65)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSetResolver.visitArtifacts(ResolvedArtifactSetResolver.java:62)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSetResolver.lambda$visitInUnmanagedWorkerThread$0(ResolvedArtifactSetResolver.java:58)
	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsUnmanagedWorkerThread(DefaultWorkerLeaseService.java:140)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSetResolver.visitInUnmanagedWorkerThread(ResolvedArtifactSetResolver.java:58)
	at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultSelectedArtifactSet.visitArtifacts(DefaultSelectedArtifactSet.java:59)
	at org.gradle.api.internal.artifacts.configurations.DefaultArtifactCollection.lambda$new$0(DefaultArtifactCollection.java:46)
	at org.gradle.internal.model.CalculatedValueContainerFactory$SupplierBackedCalculator.calculateValue(CalculatedValueContainerFactory.java:74)
	at org.gradle.internal.model.CalculatedValueContainer$CalculationState.lambda$attachValue$0(CalculatedValueContainer.java:229)
	at org.gradle.internal.Try.ofFailable(Try.java:41)
Caused by: java.io.UncheckedIOException: Could not read workspace metadata from C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin
	at org.gradle.internal.execution.history.impl.DefaultImmutableWorkspaceMetadataStore.loadWorkspaceMetadata(DefaultImmutableWorkspaceMetadataStore.java:60)
	at org.gradle.internal.execution.steps.AssignImmutableWorkspaceStep.loadImmutableWorkspaceIfConsistent(AssignImmutableWorkspaceStep.java:147)
	at org.gradle.internal.execution.steps.AssignImmutableWorkspaceStep.loadImmutableWorkspaceIfExists(AssignImmutableWorkspaceStep.java:129)
	at org.gradle.internal.execution.steps.AssignImmutableWorkspaceStep.execute(AssignImmutableWorkspaceStep.java:120)
	at org.gradle.internal.execution.steps.AssignImmutableWorkspaceStep.execute(AssignImmutableWorkspaceStep.java:90)
	at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:46)
	at org.gradle.internal.execution.steps.IdentityCacheStep.executeInCache(IdentityCacheStep.java:80)
	at org.gradle.internal.execution.steps.IdentityCacheStep.lambda$executeDeferred$0(IdentityCacheStep.java:60)
	at org.gradle.cache.Cache.lambda$get$0(Cache.java:31)
	at org.gradle.cache.ManualEvictionInMemoryCache.get(ManualEvictionInMemoryCache.java:30)
	at org.gradle.cache.internal.DefaultCrossBuildInMemoryCacheFactory$CrossBuildCacheRetainingDataFromPreviousBuild.get(DefaultCrossBuildInMemoryCacheFactory.java:255)
	at org.gradle.cache.Cache.get(Cache.java:31)
	at org.gradle.internal.execution.steps.IdentityCacheStep.lambda$executeDeferred$1(IdentityCacheStep.java:58)
	at org.gradle.internal.Deferrable$3.completeAndGet(Deferrable.java:117)
	at org.gradle.internal.Deferrable$1.completeAndGet(Deferrable.java:59)
	at org.gradle.api.internal.artifacts.transform.TransformStep.doTransform(TransformStep.java:99)
	at org.gradle.api.internal.artifacts.transform.TransformStep.lambda$createInvocation$0(TransformStep.java:83)
	at org.gradle.internal.Deferrable$3.completeAndGet(Deferrable.java:117)
	at org.gradle.internal.Deferrable.lambda$flatMap$0(Deferrable.java:80)
	at org.gradle.internal.Deferrable$3.completeAndGet(Deferrable.java:117)
	at org.gradle.api.internal.artifacts.transform.TransformingAsyncArtifactListener$TransformedArtifact.finalizeValue(TransformingAsyncArtifactListener.java:209)
	at org.gradle.api.internal.artifacts.transform.TransformingAsyncArtifactListener$TransformedArtifact.run(TransformingAsyncArtifactListener.java:147)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$QueueWorker.execute(DefaultBuildOperationExecutor.java:161)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:272)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.doRunBatch(DefaultBuildOperationQueue.java:253)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$0(DefaultBuildOperationQueue.java:238)
	at org.gradle.internal.resources.AbstractResourceLockRegistry.whileDisallowingLockChanges(AbstractResourceLockRegistry.java:50)
	at org.gradle.internal.work.DefaultWorkerLeaseService.whileDisallowingProjectLockChanges(DefaultWorkerLeaseService.java:236)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$1(DefaultBuildOperationQueue.java:238)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:264)
	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:128)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:224)
	at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:192)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: java.io.FileNotFoundException: C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin (The system cannot find the file specified)
	at org.gradle.internal.execution.history.impl.DefaultImmutableWorkspaceMetadataStore.loadWorkspaceMetadata(DefaultImmutableWorkspaceMetadataStore.java:45)
	... 38 more

CONFIGURE FAILED in 6s

解决方法

Caused by: java.io.UncheckedIOException: Could not read workspace metadata from C:\Users\itmob.cn\.gradle\caches\8.8\transforms\5e58dde8d255b1276439bb7095fc102c\metadata.bin

上述异常信息中提到无法读取 Gradle 8.8 的缓存目录中的元数据,缓存文件出现问题。

解决办法:根据异常信息将缓存目录下报错的 Gradle 版本的缓存文件全部删除,然后重新同步项目即可。比如:上文异常的缓存在 C:\Users\itmob.cn\.gradle\caches 目录下,有问题的版本是 8.8,删除 8.8 这个目录即可。

  1. 由于 Android Studio 正在占用某些文件,删除缓存可能失败,可以先关闭 Android Studio 再删除。
  2. 删除的目录中包含下载的 Gradle 依赖项,在下一次构建中将重新下载,这可能需要一些时间。