Android Studio 3.1创建新项目报错:找不到gradle-core.jar
Hey there, I’ve dealt with this exact headache when upgrading to Android Studio 3.1—totally understand how annoying it is when your new project won’t build right out the gate. Let’s go through the proven fixes that worked for me and fellow developers:
1. Double-check your root build.gradle repository configuration
This is the most common culprit. Starting with Android Gradle Plugin 3.0+, most core dependencies (including gradle-core) are hosted on Google’s Maven repository, not just JCenter. Make sure your root-level build.gradle includes the google() repository before other repos in both buildscript and allprojects blocks:
buildscript { repositories { google() // Critical: Must be present and prioritized jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.0' // Match your plugin version } } allprojects { repositories { google() jcenter() } }
After updating this file, click Sync Project with Gradle Files in the toolbar to apply changes.
2. Clear Gradle caches and restart Android Studio
Corrupted cached files often cause this kind of missing dependency error. Here’s how to fix it:
- Go to
File > Invalidate Caches / Restartin Android Studio. - Select
Invalidate and Restart—this will clear all cached data and reboot the IDE. - If that doesn’t work, manually delete the
.gradlefolder (found in your project root directory, or in your user home folder:~/.gradleon Mac/Linux,C:\Users\YourName\.gradleon Windows) and then reopen the project to trigger a fresh sync.
3. Verify your Gradle wrapper version matches the plugin
Android Gradle Plugin 3.1.0 requires Gradle 4.4 or later. Check your gradle/wrapper/gradle-wrapper.properties file to ensure the distribution URL points to the correct version:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
If it’s set to an older version, update it and sync the project—Android Studio will automatically download the required Gradle version if needed.
4. Manual fallback: Download the jar and add it to your local Maven repo
If the above steps fail, you can manually grab the missing gradle-core-3.1.0.jar (and its corresponding .pom file) and place them in your local Maven repository’s path:
- Navigate to your local Maven repo (usually
~/.m2/repository/com/android/tools/build/gradle-core/3.1.0or the equivalent on Windows). - Create the
3.1.0folder if it doesn’t exist. - Copy the downloaded
gradle-core-3.1.0.jarandgradle-core-3.1.0.pominto this folder, then sync your project again.
If you’re still stuck, check the full Gradle Console output (View > Tool Windows > Gradle > Toggle Console) for more specific error messages—sometimes there’s a hidden issue with other dependencies causing this failure.
内容的提问来源于stack exchange,提问作者VSB

