【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

1、 错误描述

今天在Android Studio中,使用gradle命令的时候,出现了如下所示的错误:

D:\GitLab Source\XTCLint>gradlew clean uploadArchives --stacktrace
Starting a Gradle Daemon, 1 busy and 1 incompatible Daemons could not be reused, use --status for details FAILURE: Build failed with an exception. * What went wrong:
A problem occurred configuring root project 'XTCLint'.
> Could not resolve all dependencies for configuration ':classpath'.
> Timeout waiting to lock artifact cache (C:\Users\000\.gradle\caches\modules-2). It is currently in use by another Gradle instance.
Owner PID: 10736
Our PID: 204
Owner Operation: resolve configuration ':classpath'
Our operation:
Lock file: C:\Users\000\.gradle\caches\modules-2\modules-2.lock * Try:
Run with --info or --debug option to get more log output.

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

完整的错误日志如下所示:

D:\GitLab Source\XTCLint>gradlew clean uploadArchives --stacktrace
Starting a Gradle Daemon, 1 busy and 1 incompatible Daemons could not be reused, use --status for details FAILURE: Build failed with an exception. * What went wrong:
A problem occurred configuring root project 'XTCLint'.
> Could not resolve all dependencies for configuration ':classpath'.
> Timeout waiting to lock artifact cache (C:\Users\000\.gradle\caches\modules-2). It is currently in use by another Gradle instance.
Owner PID: 10736
Our PID: 204
Owner Operation: resolve configuration ':classpath'
Our operation:
Lock file: C:\Users\000\.gradle\caches\modules-2\modules-2.lock * Try:
Run with --info or --debug option to get more log output. * Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'XTCLint'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:72)
at org.gradle.configuration.project.LifecycleProjectEvaluator.access$000(LifecycleProjectEvaluator.java:33)
at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:53)
at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:50)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:628)
at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:129)
at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:161)
at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:158)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':classpath'.
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.wrapException(ErrorHandlingConfigurationResolver.java:96)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.resolveGraph(ErrorHandlingConfigurationResolver.java:68)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$3.execute(DefaultConfiguration.java:443)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$3.execute(DefaultConfiguration.java:436)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveGraphIfRequired(DefaultConfiguration.java:436)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveToStateOrLater(DefaultConfiguration.java:411)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.doGetFiles(DefaultConfiguration.java:518)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:356)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
at org.gradle.api.internal.initialization.DefaultScriptHandler.getScriptClassPath(DefaultScriptHandler.java:69)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.defineScriptHandlerClassScope(DefaultPluginRequestApplicator.java:193)
at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:78)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
... 55 more
Caused by: org.gradle.cache.internal.LockTimeoutException: Timeout waiting to lock artifact cache (C:\Users\000\.gradle\caches\modules-2). It is currently in use by another Gradle in
stance.
Owner PID: 10736
Our PID: 204
Owner Operation: resolve configuration ':classpath'
Our operation:
Lock file: C:\Users\000\.gradle\caches\modules-2\modules-2.lock
at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.lock(DefaultFileLockManager.java:269)
at org.gradle.cache.internal.DefaultFileLockManager$DefaultFileLock.<init>(DefaultFileLockManager.java:138)
at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:86)
at org.gradle.cache.internal.DefaultFileLockManager.lock(DefaultFileLockManager.java:73)
at org.gradle.cache.internal.LockOnDemandCrossProcessCacheAccess.incrementLockCount(LockOnDemandCrossProcessCacheAccess.java:94)
at org.gradle.cache.internal.LockOnDemandCrossProcessCacheAccess.acquireFileLock(LockOnDemandCrossProcessCacheAccess.java:136)
at org.gradle.cache.internal.DefaultCacheAccess.onStartWork(DefaultCacheAccess.java:425)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:182)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:170)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:129)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:191)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:56)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:41)
at org.gradle.api.internal.artifacts.ivyservice.DefaultConfigurationResolver.resolveGraph(DefaultConfigurationResolver.java:119)
at org.gradle.api.internal.artifacts.ivyservice.ShortCircuitEmptyConfigurationResolver.resolveGraph(ShortCircuitEmptyConfigurationResolver.java:72)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.resolveGraph(ErrorHandlingConfigurationResolver.java:66)
... 73 more BUILD FAILED Total time: 1 mins 2.928 secs D:\GitLab Source\XTCLint>

2、 解决错误

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

选择【File】–>【Invalidate Caches/Restart】,然后弹出如下所示的弹框

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

选择【Invalidate and Restart】重启Android Studio

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

点击【Exit】,发现半天都没有重启,下面强制关闭掉 Android Studio

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

重启Android Studio之后,运行gradle命令移入报错。

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

D:\GitLab Source\XTCLint>gradlew clean uploadArchives

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'XTCLint'.
> Could not resolve all dependencies for configuration ':classpath'.
> Timeout waiting to lock artifact cache (C:\Users\000\.gradle\caches\modules-2). It is currently in use by another Gradle instance.
Owner PID: 10736
Our PID: 204
Owner Operation: resolve configuration ':classpath'
Our operation:
Lock file: C:\Users\000\.gradle\caches\modules-2\modules-2.lock * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 1 mins 0.864 secs D:\GitLab Source\XTCLint>

下面使用暴力方法,将上面提示的 C:\Users\000.gradle\caches\modules-2 目录下的lock文件删掉,如下所示:

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

将上图所示的文件 modules-2.lock 删除掉。

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

如上图所示,提示文件无法删除。使用【电脑管家】的【文件粉碎】功能强行删除掉。

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

接着重新运行gradle命令,则可以正常运行了,如下所示:

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .


【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!

转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/77851598

【我的Android进阶之旅】解决AndroidStudio编译时报错:Timeout waiting to lock artifact cache .

上一篇:百度bae定时任务使用方法


下一篇:【androidstudio】将eclipse的项目导入android studio