升级Android Gradle插件后出现403错误,回退版本仍无效
Hey there, let's sort out that frustrating 403 error you're hitting when trying to download the Gradle distribution. Here's what's going on and how to fix it step by step:
Why This Happens
The 403 response means the server is refusing your request to download gradle-4.4-rc-3-all.zip. This is almost certainly because Gradle's release candidate (RC) versions get pulled down once the official stable version is available. Gradle 4.4 has been out as a stable release for a while now, so the RC-3 build is no longer hosted on services.gradle.org.
Even when you rolled back to Android Gradle Plugin 3.1.0-alpha05, the issue persisted because the Gradle wrapper configuration (which controls which Gradle version your project uses) is independent of the AGP version. Your wrapper was still pointing to the deprecated RC-3 build.
Step-by-Step Fix
1. Update the Gradle Wrapper Configuration
Open the gradle/wrapper/gradle-wrapper.properties file in your project root directory. Look for the distributionUrl line and replace the RC version with the stable Gradle 4.4 release:
Before:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-rc-3-all.zip
After:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
2. Clear Stale Gradle Cache
To avoid any leftover cached files causing issues, delete the old RC-3 distribution folder from your local Gradle cache:
- On macOS/Linux: Navigate to
~/.gradle/wrapper/distsand delete the folder named something likegradle-4.4-rc-3-all - On Windows: Go to
C:\Users\<YourUsername>\.gradle\wrapper\distsand delete the correspondinggradle-4.4-rc-3-allfolder
3. Sync or Rebuild Your Project
Now, either:
- Click the "Sync Project with Gradle Files" button in Android Studio, or
- Run the command in your project root:
./gradlew clean build # macOS/Linux gradlew clean build # Windows
This should pull down the stable Gradle 4.4 distribution successfully, and your build should work again with either AGP 3.1.0-alpha05 or alpha06.
内容的提问来源于stack exchange,提问作者user6683139

