43

Here's the output:

11:57:04 AM Gradle 'KeddreaderProject' project refresh failed: Cause: org.gradle.internal.service.ServiceLocator.([Ljava/lang/ClassLoader;)V:

I've tried to remove .gradle folder, but it doesn't help. What can be the problem?

Edit: I get this error even when I try to import any other project on Ubuntu 13.10. But on Windows everything works (with the the same version of Android Studio) well.

s0nerik
  • 681
  • 2
  • 7
  • 14
  • try changing gradle plugin version to 0.6.3 in build.gradle and gradle wrapper to version 1.8 in gradle/wrapper/gradle-wrapper.properties (change the distributionUrl). then run `./gradlew clean` and `./gradlew build --refresh-dependencies` – Gal Ben-Haim Nov 09 '13 at 10:44
  • Build went successful, but problem with refreshing is still here. – s0nerik Nov 09 '13 at 11:30
  • I have the same issue, using `./gradlew` or even `gradle` works flawlessly but android-studio complains when building with "org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle installation '/home/rndstr/.gradle/wrapper/dists/gradle-1.8-bin/vruqmccc8532n7gr46qavsii8/gradle-1.8'.: Could not execute build using Gradle installation '/home/rndstr/.gradle/wrapper/dists/gradle-1.8-bin/vruqmccc8532n7gr46qavsii8/gradle-1.8'." and the error mentioned above when trying to sync project – rndstr Nov 09 '13 at 14:44
  • @rndstr, does it began with 0.3.3 update for you? – s0nerik Nov 09 '13 at 14:56
  • 3
    @s0nerik I updated this morning (about 1h before I wrote my comment) and IIRC it was from 0.3.2 to 0.3.4 (Linux). Edit: I also created a new project which leads to the same error, so it is not code-related – rndstr Nov 09 '13 at 18:26
  • looking in the android-studio log, I can see the following: Gradle project resolve error \n org.gradle.tooling.GradleConnectionException: Could not fetch model of type 'BuildEnvironment' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.8-all.zip'. But I can fairly well access that URL – rndstr Nov 09 '13 at 18:39
  • @rndstr, in my case this bug appeared in 0.3.3 version and still there. I can only suggest that the problem is here: "Ljava/lang/ClassLoader", seems like a typo. – s0nerik Nov 09 '13 at 18:52
  • @s0nerik it's not a typo http://stackoverflow.com/questions/5085889/l-array-notation-where-does-it-come-from – rndstr Nov 10 '13 at 09:34
  • @rndstr If it so, then I have no idea what's going wrong in Android Studio. :( – s0nerik Nov 10 '13 at 09:44
  • 2
    rm android-studio/plugins/gradle/lib/gradle-*-1.8.jar try this guys worked for me – bugraoral Nov 11 '13 at 09:25
  • 1
    http://code.google.com/p/android/issues/detail?id=62067 – Industrial-antidepressant Nov 11 '13 at 09:53
  • 1
    Looks like a bug in AS 3.4 – Industrial-antidepressant Nov 11 '13 at 09:54
  • Use the previous release: http://tools.android.com/download/studio/canary/0-3-2 – Industrial-antidepressant Nov 11 '13 at 10:06

13 Answers13

26

Check the Gradle home path after the update to version 1.5. It should be ../gradle-2.8.

enter image description here

Darius
  • 10,762
  • 2
  • 29
  • 50
23

Most people do not read the comments so to summarize (Thanks to @Industrial-antidepressant and @wrecker):

As suggested in a bug ticket you should try the following:

  1. Close Android Studio
  2. go to android-studio/plugins/gradle/lib
  3. Delete (or better move them somewhere to have a backup) all gradle-*-1.8 files
  4. Start Android Studio again and rebuild/refresh.

It should work. Make sure to star the above bug ticket to get informed.

Little tip: Try the new compile setting Settings -> Compiler -> Gradle and activate the third in-process build for a speed up. Depending on your project setting you might want to select the first one as well. With that my project build time reduced to 2-4 seconds (before 20+ seconds).

serv-inc
  • 35,772
  • 9
  • 166
  • 188
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • 13
    Not working, gives me NoClassDefFoundError: org/gradle/tooling/ProgressListener: org/gradle/tooling/ProgressListener when I click on Rebuild – Marian Klühspies Jan 18 '14 at 15:12
  • 2
    `NoClassDefFoundError: org/gradle/tooling/model/UnsupportedMethodException` – Iman Marashi Jan 25 '16 at 16:46
  • @ImanMarashi You put an error line in a comment and expect what? Help? Applause? It is like screaming "hello" in middle earth and expecting Peter Pan to come to help. – WarrenFaith Jan 26 '16 at 08:48
  • @WarrenFaith I do all your commands, but I still got the error. Understanding this is very simple. To better understand what I see and I guide you to [this link](http://stackoverflow.com/questions/35000287/could-not-initialize-class-org-gradle-tooling-internal-consumer-loader-defaultto). – Iman Marashi Jan 26 '16 at 18:25
  • This helped, Also clear cache and if possible point the Gradle to the latest. – DearDhruv Apr 11 '16 at 05:49
  • I deleted them and restarted Android Studio and got NoClassDefFoundError and then restored the deleted files and now project refresh works. – Harsh Feb 17 '17 at 02:45
20

File -> Invalidate Caches / Restart -> Invalidate and Restart worked for me.

dinesharjani
  • 545
  • 6
  • 14
  • This fixed my issue when I was replacing local aar with remote dependency. Thanks man! – pkk May 26 '15 at 15:44
11

I tried everything, nothing worked.then I tried the following steps and it worked

  1. close Android studio

  2. go to "My Documents"

  3. delete the following folders a).android, b).androidstudio1.5, c).gradle

  4. start Android studio and enjoy...

It seems stupid but works...

Bhaumik Belani
  • 652
  • 1
  • 8
  • 19
2

This might be too late to answer. But this may help someone.

In my case there was problem of JDK path.

I just set proper JDK path for Android Studio 2.1

File -> Project Structure -> From Left Side Panel "SDK Location" -> JDK Location -> Click to select JDK Path

pgp
  • 89
  • 3
1

Although this has been answered a long time ago, I had the same problem with an app after updating to

Gradle 2.1.2

The solution I found (on top of the one given by @WarrenFaith was to:

File -> Synchronize

This solved all the errors generated by the Gradle update.

1

Use this in project.gradle:

buildscript {
    repositories 
    {
        mavenCentral()
    }

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

allprojects {
    repositories {
        mavenCentral()
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Syed Danish Haider
  • 1,334
  • 11
  • 15
1

Make sure that nothing is interfering with your app files (specially in Windows), in my case this problem arise due to a text editor that was holding some XML file and Android Studio wasn't able to modify it.

D.Snap
  • 1,704
  • 1
  • 22
  • 15
0
  1. Go to C://Users//
  2. Remove .AndroidStudio2.x
  3. Open Android Studio and config for initialization again.
Karoshi
  • 29
  • 1
  • 7
0

SDK wasn't downloaded

so turned on the internet connection and after restarting the Android Studio

it showed a pop up to download 800mb data click on yes and issue gets resolved

Harshit Sharma
  • 194
  • 1
  • 5
0
  • Go to Terminal and type clearw Gradle
  • Press Enter
  • Goto file menu, choose Invalidate Caches /Restart
  • Press Yes
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
-2

Close your project, and then import project. That work for me. It's a simply way.

good luck.

-2
  1. Close Android Studio
  2. Go to C:\Users\Username
  3. delete the .gradle folder

That's it you are done