You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调试时遇Gradle锁协议错误:期望3却找到0,按方案处理仍未解决

Fixing "Unexpected lock protocol found in lock file. Expected 3, found 0" in Gradle 4.4 + Android Studio 3.1.2

Hey there, I know how frustrating it is when the common fix (deleting the root .gradle folder) doesn’t resolve this lock protocol error. Let’s dive into more targeted solutions tailored to your specific setup:

  • Invalidate Android Studio Caches & Restart
    Sometimes Android Studio’s internal cached state clashes with Gradle’s lock files. Head to File > Invalidate Caches / Restart, then select Invalidate and Restart. This clears AS’s stale caches and gives your project a fresh start.

  • Delete Module-Level .gradle & .build Folders
    The root .gradle folder isn’t the only hiding spot for stale lock files. Navigate to each module in your project (like the app module) and delete both the .gradle and .build subfolders. After removing these, go back to Android Studio and re-sync your project.

  • Verify Gradle Wrapper Configuration
    Open your project’s root gradle/wrapper/gradle-wrapper.properties file and double-check the distributionUrl points to the correct Gradle 4.4 version:

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
    

    Save the file, then open a terminal in your project root and run:

    # For Mac/Linux
    ./gradlew clean build
    
    # For Windows
    gradlew clean build
    

    This forces Gradle to re-download the correct version and rebuild your project from scratch.

  • Clear User-Level Gradle Caches
    Stale caches in your user-specific Gradle directory can also trigger this issue. Locate and delete these folders:

    • Windows: C:\Users\<Your Username>\.gradle\caches and C:\Users\<Your Username>\.gradle\wrapper
    • Mac/Linux: ~/.gradle/caches and ~/.gradle/wrapper
      Once deleted, restart Android Studio and sync your project again.
  • Manually Remove Remaining Lock Files
    Do a full search across your project directory for any files ending in .lock (e.g., .gradle/4.4/taskHistory/*.lock). Delete all these lock files, then try building your project once more.

If none of these steps work, a last-resort option is to create a new Android Studio project with the same Gradle/AS version, then migrate your source code, resources, and dependencies over. Sometimes corrupted project configuration files cause persistent lock issues that are hard to track down.

内容的提问来源于stack exchange,提问作者Don

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:54:19