Team Services Git构建失败:gradlew返回码1(Android开发新手求助)
Hey there! Let's tackle that frustrating gradlew failed with return code: 1 error you're facing with your Android CI build in Azure DevOps (formerly Team Services). Since you've already enabled System.debug=true and uploaded the logs, we can use those to get to the bottom of this—let's break down what to do next.
gradlew return code: 1 in Azure DevOps Android Builds First, Uncover the Real Issue in Your Debug Logs
The return code: 1 is just a generic failure signal—the actual problem is hidden in the detailed debug logs. Here’s what to scan for:
- Dependency resolution failures: Look for lines like
Could not resolve com.android.support:appcompat-v7:28.0.0or timeout messages. Even with proxy setup, sometimes repo URLs (like Google's Maven repo or Maven Central) aren't whitelisted, or the build agent can't reach them through the proxy. - Lint violations: If your pipeline runs lint checks, a critical lint error will halt the build. Watch for lines like
Lint found errors in the project; aborting buildor specific rule failures (e.g.,MissingTranslation). - Build config typos: Check for mistakes in your
build.gradlefiles—incorrect SDK versions, missing plugins, or invalid signing configurations. Lines starting with* What went wrong:are your best friend here; they’ll point directly to the root cause. - Permission issues: Sometimes the build agent lacks write access to the
.gradlecache directory. Look forPermission deniederrors when the build tries to create or modify files.
Double-Check Your Proxy Setup (Even If You Think It’s Correct)
Proxy configurations can be tricky—verify these details:
- Ensure proxy variables (
http_proxy,https_proxy,no_proxy) are set both on the build agent machine and as pipeline variables in Azure DevOps. Forno_proxy, include localhost, 127.0.0.1, and any internal repos your project uses. - Test connectivity from the build agent: Run
curl https://maven.google.comon the agent machine to confirm it can reach Google’s Maven repo through the proxy. If this fails, your proxy settings need adjustment.
Test the Build Locally to Narrow Down the Problem
Before pushing code, run the exact same Gradle command your pipeline uses on your local machine. For example, if your pipeline runs ./gradlew assembleRelease, execute that locally. If it fails here too, the issue is with your project’s setup (not the CI pipeline), which makes debugging way easier.
Quick Fixes to Try
- Clear the Gradle cache: On the build agent, delete the
.gradledirectory in the pipeline workspace, or add a step to run./gradlew cleanbefore the build task. - Update your Gradle wrapper: Outdated Gradle versions can clash with newer Android SDKs. Run
./gradlew wrapper --gradle-version <your-compatible-latest-version>locally, commit the changes, and push to Git. - Temporarily disable lint checks: To rule out lint as the culprit, add this to your app-level
build.gradle:
If the build passes, go back and fix the specific lint errors that were blocking it.lintOptions { abortOnError false }
Once you spot the exact error line in your debug logs, you can zero in on the precise fix. For example, if it’s a dependency error, you might need to add the correct repo to your build.gradle or adjust your proxy to allow access to that repository.
内容的提问来源于stack exchange,提问作者Pronoy999

