Travis CI构建Android项目时Gradle版本不兼容问题求助
Let's break down what's going wrong and how to fix this issue:
Root Cause
The error occurs because your Travis configuration is mixing system-level Gradle with the Gradle wrapper. Your install step runs gradle wrapper --gradle-version 4.4, but this uses Travis's default Gradle 4.0.1 to generate the wrapper—this is unnecessary (since you already have valid wrapper files in your repo) and triggers version conflicts. Additionally, setting executable permissions on gradle-wrapper.jar is redundant (it's a JAR file, not a script) and can be removed.
Step-by-Step Solution
Clean up your
.travis.ymlconfiguration
Remove theinstallstage entirely (you don't need to regenerate the wrapper) and remove the unnecessary chmod for the JAR file. Here's the corrected config:language: android android: components: - tools - platform-tools - build-tools-26.0.2 - android-26 - extra-google-google_play_services - extra-google-m2repository - extra-android-m2repository - addon-google_apis-google-26 before_script: - chmod a+x gradlew script: - ./gradlew buildVerify your
gradle-wrapper.properties
Confirm your existing file correctly points to Gradle 4.4 (which you already have set up):#Fri May 25 21:05:26 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zipConfirm wrapper files are properly committed
Double-check thatgradlew,gradle-wrapper.properties, andgradle-wrapper.jarare all present in your repo and committed correctly.
Why This Works
By removing the install step, Travis will use your pre-configured Gradle wrapper instead of the system's outdated Gradle 4.0.1. The wrapper will automatically download Gradle 4.4 (as specified in gradle-wrapper.properties) and use it to run your build—this version meets the minimum requirement of 4.1 for the Android plugin, resolving the mismatch error.
内容的提问来源于stack exchange,提问作者ir2pid

