Android Studio 3.1.0项目同步失败:找不到builder.jar (com.android.tools.build:builder:3.1.0)
Hey there, let's work through this Gradle sync error you're hitting with Android Studio 3.1.0 and Gradle 4.6. I've dealt with similar dependency resolution headaches before, so here are actionable fixes to try out:
Verify your repository configuration
Open your project's rootbuild.gradlefile and make sure the Google Maven repository is listed first in thebuildscriptrepositories section. Older Android Studio versions might not recognize the shorthandgoogle()yet, so you can use the full URL instead:buildscript { repositories { // Use this line if google() doesn't work for your AS version maven { url 'https://dl.google.com/dl/android/maven2/' } jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.0' } }Putting the Google repo first ensures Gradle checks it before other repositories, which avoids missing Google-specific dependencies like the builder jar.
Manually add the builder jar to your local Gradle cache
If the automatic download is failing, you can grab the jar manually and place it in your local Gradle cache:- Locate your local Gradle cache directory:
- On macOS/Linux:
~/.gradle/caches/modules-2/files-2.1/com.android.tools.build/builder/3.1.0/ - On Windows:
C:\Users\[YourUsername]\.gradle\caches\modules-2\files-2.1\com.android.tools.build\builder\3.1.0\
- On macOS/Linux:
- Download the
builder-3.1.0.jarfile (you can find it via Maven repository searches) and place it in the folder above (you might need to create the 3.1.0 subfolder if it doesn't exist). - Restart Android Studio and re-sync your project.
- Locate your local Gradle cache directory:
Clear Gradle caches and restart
Corrupted cache files often cause these kinds of issues. Try these steps:- Go to
File > Invalidate Caches / Restartin Android Studio. - Select
Invalidate and Restartto clear both IDE and Gradle caches. - Once the IDE restarts, trigger a Gradle sync again.
Alternatively, you can manually delete the entire.gradle/cachesfolder on your system, then re-sync.
- Go to
Check network and proxy settings
A flaky network or misconfigured proxy can block Gradle from accessing the Google Maven repo. Try:- Disabling any VPN or proxy temporarily to see if the sync works.
- Verifying your proxy settings in
File > Settings > Appearance & Behavior > System Settings > HTTP Proxyto ensure they allow access to Google's Maven servers.
内容的提问来源于stack exchange,提问作者Salim13i

