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

Android Studio新手求助:Gradle同步失败(找不到gradle:3.1.1)

Fixing "Could not find com.android.tools.build:gradle:3.1.1" Error

Hey there! I remember hitting this exact issue when I was first starting out with Android Studio—Gradle sync errors can feel super frustrating, but let’s break down how to fix this step by step.

Step 1: Verify Your Project-Level build.gradle Repository Config

First, open your project’s root build.gradle file (the one in the main project folder, not the app module). Make sure you have the correct repositories listed in both the buildscript and allprojects blocks. Google’s Maven repository is essential for accessing Android Gradle plugin versions, and Maven Central has replaced JCenter for most dependencies now.

Here’s what the file should look like:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.1.1"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

Double-check that you haven’t missed either repository—this is the most common reason Gradle can’t find the plugin.

Step 2: Use the Default Gradle Wrapper

Android Studio’s Gradle wrapper handles downloading the correct Gradle version automatically. To make sure this is enabled:

  • Go to File > Settings > Build, Execution, Deployment > Gradle (on Mac, it’s Android Studio > Preferences > Build, Execution, Deployment > Gradle)
  • Ensure the option "Use default Gradle wrapper (recommended)" is selected.
  • Click "Apply" then "OK".

Step 3: Clear Caches and Restart Android Studio

Sometimes old cached files can cause issues. Let’s wipe those and start fresh:

  • Go to File > Invalidate Caches...
  • Check the box next to "Invalidate and Restart"
  • Click "Invalidate" to restart Android Studio. This will clear old cache files and force Gradle to re-download the plugin from the repositories.

Optional: Upgrade to a Newer Gradle Plugin Version

The 3.1.1 version of the Android Gradle plugin is pretty outdated (it’s from 2018) and might not play nicely with newer versions of Android Studio. If the above steps don’t work, or if you want a more stable setup, consider upgrading:

  1. In your root build.gradle, change the classpath to a newer, supported version. For example:
    classpath "com.android.tools.build:gradle:7.0.4"
    
  2. Open gradle/wrapper/gradle-wrapper.properties and update the distributionUrl to match the required Gradle version for that plugin (7.0.4 uses Gradle 7.0.2):
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
    
  3. Sync your project again—Android Studio will guide you through any additional setup if needed.

Give these steps a try, and your Gradle sync should work smoothly once you’ve got the right repositories and cache cleared.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:21:34