I'm lost and desperate! Gradle is confused abo

2019-09-06 15:24发布

问题:

I just upgraded Android studio and now Android Studio complaints about Gradle, saying:

You are using Gradle version 1.8, which is not supported. Please use version 1.9. 

So under Preferences > Compiler > Gradle, I changed the Gradle executable to /usr/local/Cellar/gradle/1.8/libexec. After rebuilding, Android Studio then complaints again, saying

Gradle version 1.8 is required. Current version is 1.9. 
If using the gradle wrapper, try editing the distributionUrl in /Applications/Android Studio.app/bin/gradle/wrapper/gradle-wrapper.properties to gradle-1.9-all.zip.

I don't know anything about a Gradle wrapper, but in my gradle.build I've got these lines for the gradle version:

dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
}

Does anybody know how I can fix this? I'm really stuck and quite desperate! All tips are welcome!

回答1:

Switch to the gradle Android plugin version 0.7+

dependencies {
    classpath 'com.android.tools.build:gradle:0.7.+'
}

Then you should be able to build with gradle version 1.9.



回答2:

Make sure all your build.gradle files in the project use gradle 1.9 as dependency

  buildscript {
       repositories {
          mavenCentral()
       }
  dependencies {
     classpath 'com.android.tools.build:gradle:0.7.+'
   }
  }

Also check your Gradle Wrapper properties file. Its available in your project structure. It must point to gradle 1.9. AFAIK you will get pop up this fix that automatically but just confirm



回答3:

Update both the build.gradle dependency as mentioned by keyboardsurfer and pyus13 and the distribution url found in gradle-wrapper.properties under /gradle/wrapper/.

Example:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip