Android Studio - Unable to build project - GradleConnectionException
Asked Answered
J

4

10

I'm on Android Studio 0.3.2. Since I upgraded from previous version, unable to build existing projects.

I'm consistently having gradle integration problems. I spend more time sorting out gradle than writing any code. I've been stumped for one week now!

I get the error mentioned on so many posts, but after reading for hours none of the solutions have worked for me.

org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle installation 'C:\Users\Adrian.gradle\wrapper\dists\gradle-1.8-all\2kopnp0i5dq014k75fp36m3vd5\gradle-1.8'.: Could not execute build using Gradle installation 'C:\Users\Adrian.gradle\wrapper\dists\gradle-1.8-all\2kopnp0i5dq014k75fp36m3vd5\gradle-1.8'.

I checked my gradle version using the built in terminal window in android studio.

gradlew --version in terminal window

My gradle.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="useAutoImport" value="true" />
      </GradleProjectSettings>
      <GradleProjectSettings>
        <option name="distributionType" value="DEFAULT_WRAPPED" />
        <option name="externalProjectPath" value="D:\Users\Adrian\AndroidStudioProjects\SupaScaleProject" />
        <option name="useAutoImport" value="true" />
      </GradleProjectSettings>
    </option>
    <option name="serviceDirectoryPath" value="$USER_HOME$/.gradle" />
  </component>
</project>

My gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-all.zip  

My build.gradle

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

   repositories {
        mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }

    buildTypes {
        release {
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }

        debug {
            runProguard false
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }

 }

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile files('libs/achartengine-1.1.0.jar')
}

I do a build from the Terminal: gradlew compileDebug and the build is successful!

enter image description here

Now I build form the Menu bar Build -> Rebuild Project (in AndroidStudio 0.3.2):

enter image description here

I really don't know where to look anymore. Any help will be appreciated.

Oh .. yes I have deleted all the files in .gradle/wrapper/dists/ and allowed Android Studio to download for me.

Thanks in advance.

Adrian

Following @joucks comment, I noticed the following at http://tools.android.com/knownissues:

enter image description here

So I changed my build.gradle to classpath 'com.android.tools.build:gradle:0.6.3' unfortunately still the same result.

Thereafter I updated the compileSDKVersion to 19, and the buildToolsVersion to "19.0.0", hoping for some success. Unfortunately none. Yes .. and before you ask, my SDK-Manager is up to date with all the latest files.

Joiejoin answered 8/11, 2013 at 13:51 Comment(3)
just want to mention, that I can do a gradlew compileDebug from Terminal, then gradlew installDebug to install on my device, and the program works as expected.Joiejoin
No I didn't Erik. I unistalled the lot, and moved all my project to 0.3.6 I was still getting odd gradle errors, then used Analyze, inspect code, and started on the top of the list and worked my way down, until it eventually compiled. I had for one some drawables (icons) that were missing in a layout that was unused, but was still causing a failure. So all I know, it is BETA, and the gradle error reporting is still very poor.Joiejoin
if you problem is solved plz mark the solution and answer your question.Macedonia
H
1

I finally figured this one out. Both times this has happened to me, rebooting my computer made it go away. "GradleConnectionException" must happen because of some memory leak or resource issue in windows.

Hotshot answered 29/11, 2013 at 19:20 Comment(1)
for me, i had to go to the command line and kill the GradleDaemon process. rebooting would have accomplished the same thing.Distressful
A
0

To quote the Android Studio 0.3.2 release notes and the details:

You also need to make sure that Gradle is using version 1.7 or later of the JDK. (And version 0.6.1 or later of the Android Gradle plugin.)

And you are using classpath 'com.android.tools.build:gradle:0.6.+'. It might be related.

Alterative answered 8/11, 2013 at 14:5 Comment(2)
I'm using JDK 1.7.0_05 and 0.6.+ will use the latest if I understood correctly, and no need to put 0.6.1 ...Joiejoin
Actually the correct version would be 0.6.3, but using 0.6.+ will select for 3 confirmed by Google in a bug report. This however does not take away the issue.Joiejoin
A
0

Check out this post: https://plus.google.com/+AndroidDevelopers/posts/1RcQews58tB A few guys report there that deleting gradle-1.8 and .gradle folder seems to fix the problem. Also, as far as I recall, problem may reooccure if there are some memory shortage issues.

Edit:

That's the thread: http://code.google.com/p/android/issues/detail?id=61259

Applecart answered 11/11, 2013 at 2:33 Comment(0)
U
0

In my case, After down-grading jdk from 1.7 u51 to 1.7 u45, all work fine.

I guess that gradle 1.8 checks revision number of JDK.

Underthecounter answered 20/1, 2014 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.