Gradle error: could not execute build using gradle

2019-01-06 17:31发布

问题:

After I updated Android Studio to version 0.2.7, I got the following error:

 org.gradle.tooling.GradleConnectionException: Could not execute build
 using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.: Could
 not execute build using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.

This is my build.gradle:

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

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

defaultConfig {
    minSdkVersion 10
    targetSdkVersion 17
}
}

Does anyone know this error? Thanks in advance!

回答1:

I had the same issue, can't say I know what caused it, but I just closed Android Studio, renamed the c:\users\MY USERNAME\.gradle directory to old-.gradle and then re-launched Android Studio.

Android studio then re-created the directory and automatically downloaded the gradle zip file and set it all up.

Seems to all be fine but to be honest I don't know what this directory is nor what the root cause of the problem was either, so proceed with caution and keep the old .gradle folder around for a bit until you're happy all is working fine.



回答2:

For me the following two steps fixed the issue:

  1. Make sure the Gradle build was successful
  2. Android Studio - File - Invalidate Caches / Restart...


回答3:

I suddenly had this issue in the morning after it working the night before. I tried all solutions here and failed.

I also tried installing another version of Gradle 1.8 and setting the gradle_home.

Tried restarting studio.

Eventually the tried and trusted method of restarting Windows worked for me.

All in all a frustrating waste of time.



回答4:

I updated to 0.3.0 and had the same issue. I had to end up changing my Gradle version to classpath 'com.android.tools.build:gradle:0.6.1+' and in build.gradle and also changing the distributionUrl to distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip in the gradle-wrapper.properties file. Then I did a local import of the Gradle file. That worked for me.



回答5:

First of all, JDK environment variable settings :

e.g) JAVA_HOME -> C:\develop\java\jdk\jdk1.8.0_25 path -> %JAVA_HOME%\bin;

eclipse Window -> preferences -> Gradle -> Arguments -> Worksapce JRE check -> jdk(jdk1.8.0_25) choice

again Run -> gradle build :)



回答6:

I had this issue as well and jaywhy13 answer was good but not enough.

I had to change a setting: Settings -> Gradle -> MyProject

There you need to check the "auto import" and select "use customizable gradle wrapper". After that it should refresh gradle and you can build again. If not try a reboot of Android Studio.



回答7:

As per answer by WarrenFaith, go to:

Settings -> Gradle -> Project-level settings

Change to Use customizable gradle wrapper.

Click OK and watch it build. If you still get an error at that stage, go back to:

Settings -> Gradle -> Project-level settings 

Change it back to Use default gradle wrapper (recommended)

Click OK. That fixed it for me.



回答8:

I entered: [C:\Users\user\].gradle\caches\1.8\scripts directory and deleted its content. I didn't had to restart anything, just removed scripts content any rerun it.



回答9:

For me, when using IntelliJ IDEA, this error arose because I had the Java SDK, rather than an Android SDK, set at the Project level.

My fix:

  • IntelliJ > File > Project Structure ...
  • Project > Project SDK > [Select] 'Android API 19 Platform (java version "1.7.0_40")'

I'm on:

  • IntelliJ IDEA: 13.1.3
  • Gradle: 1.10
  • Android Plugin for Gradle: 0.9.+


回答10:

I had the same problem on Ubuntu with Eclipse 4.3 (Kepler) and the problem was that I created the project with a minus-sign in it.

I recreated the project with no specialchars and it all worked fine



回答11:

I had the same Gradle build problems in Eclipse and by doing the following steps, the problems were solved:

  • set up project to use correct java version of java project properties-> java build path -> jre system (edit the current one, and add the correct java jdk or jre there)

  • window->Preferences ->Gradle->Arguments-> Workspace JRE (set to the correct one)

Hope this will help those who have the same problems.



回答12:

This happened to me after a java update, few things to check if you are sure your path has been set before:

  1. if the path doesn't match the latest java install folder, change it (if your in eclipse check the eclipse.ini too to make sure your using your systems default vm (ie no VM tag) )

  2. go to the java directory, there should be a 'jdk' and a 'jre' in the path, for example:

    C:\Program Files (x86)\Java\jdk1.8.0_72\jre
    

    if not you probably installed the JRE only not the JDK that

  3. finally if the lib folder of the jdk (not jre) doesnt contain tools.jar then you have a problem with the install



回答13:

I had a similar problem after doing brew install gradle. Perhaps it was because it was an older version. So I uninstalled and instead followed the gradle website's install instructions and then when I did gradle eclipse I no longer had the could not execute build using gradle distribution error.



回答14:

This problem occurred to me when I edited the configurations in Android Studio to use the Desktop. However, using the default(android) seems to work well without any issues.



回答15:

To correct this mistake very easily, If you read logs. The problem occurs because of the sudden shutdown of the IDEA. And the log files do not correctly write data. Just delete the file on the path

C:/Users/{UserName}/.Gradle/demon/{gradleVersion}/registry.bin.lock.