68

I've been using the new preview of android studio and really like it. But recently my project won't build. I get the following error:

Gradle: 
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':TestProj:compileDebug'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

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

Question is how do I enable the stack trace so I can get to the root of the error. As it is I really have no idea what's causing this.

Jonik
  • 80,077
  • 70
  • 264
  • 372
RogueX
  • 1,973
  • 2
  • 15
  • 14

8 Answers8

47

If you are using the Gradle Wrapper (the recommended option in Android Studio), you enable stacktrace by running gradlew compileDebug --stacktrace from the command line in the root folder of your project (where the gradlew file is).

If you are not using the gradle wrapper, you use gradle compileDebug --stacktrace instead (presumably).

You don't really need to run with --stacktrace though, running gradlew compileDebug by itself, from the command line, should tell you where the error is.

I based this information on this comment:

Android Studio new project can not run, throwing error

Community
  • 1
  • 1
joe_deniable
  • 2,562
  • 3
  • 28
  • 38
  • Can't thank you enough for this answer. I voted it up and wish I could vote more than once. Been a long time since I did java and it was all ant back then. The error message you see in the build messages in Android Studio led me to believe there was an issue with the integration with gradle. Running from the command line showed me there was an error in my code. Hopefully they will improve the error messages in Android Studio so jerks like me don't go down the wrong path... – jeffa00 May 30 '13 at 15:18
  • Thanks! Yes I definitely think the current error message is incredibly unhelpful the way it doesn't even hint at where to start looking for the problem, when it could so easily give you the required info! – joe_deniable May 30 '13 at 20:16
  • 1
    This is what I was after too... turned out I had a .png file that was using mixed case in the filename.. i.e. checkAvailability.png , renaming it to check_availability.png solved the problem... many thanks for your answer :) – mlo55 Jun 19 '13 at 08:17
  • 1
    @mlo55 I had the exact same issue - more importantly, this error shows up when running the "gradlew compileDebug --stacktrace" command but does *not* show up in the AndriodStudio IDE error list! – CrimsonX Jun 19 '13 at 20:17
  • i followed each single step in this answer, but it still have the same answer. any other idea that could help ? – S Gaber Jun 30 '13 at 19:14
  • such a messed up idiotic system, why don't they go back to eclipse? :-/ – M D P Sep 11 '16 at 17:52
7

Similar to @joe_deniable 's answer the thing I found with my own projects was that gradle would output that kind of error when there was a misconfiguration of my system.

I discovered that by running gradlew installDebug or similar command from the terminal I got better output as to what the real problem was.

e.g. initially it turns out my JAVA_HOME was not setup correctly. Then I discovered it encountered errors because I didn't have a package space setup correctly. Etc.

kc7zax
  • 413
  • 2
  • 8
4

The only solution I've found is to first create the project in Android Studio, then close the project, then import the project. I searched all over and could not find the root cause and all other solutions people posted didn't work.

adefran83
  • 653
  • 7
  • 10
  • 1
    Thank you! Only your solution worked for me -- close, then import. Additionally, I needed to update classpath 'com.android.tools.build:gradle:0.6.1+' in build.gradle – Maris B. Oct 23 '13 at 10:08
  • I dunno but it works like a charm! Too bad why AS should be like this. – rhavendc Jan 29 '20 at 06:39
0

OK seems like a caching issue of some sort. There was indeed an error in code with the R.id.some_id not being found but the editor was not picking it up displaying that there were no errors.

RogueX
  • 1,973
  • 2
  • 15
  • 14
0

I installed Android Studio on an old WinXP with only for me option. After install I did the new project wizard and when opening the new project a got some Gradle error with some failed path to my instalation dir. c:/Document"#¤!"#¤ and settins/...

The I uninstalled and did a new install with option for all users (C:/Programs/..) then I opend the previous created project with no errors.

So it might be a path problem. (Just spent 10 sec debugging, so I might be wrong but it solved my gradle error)

0

I found this post helpful:

"It can happen when res folder contains unexpected folder names. In my case after merge mistakes I had a folder src/main/res/res. And it caused problems."

from: "https://groups.google.com/forum/#!msg/adt-dev/0pEUKhEBMIA/ZxO5FNRjF8QJ"

user2615206
  • 71
  • 1
  • 3
0

Edit the gradle wrapper settings in gradle/wrapper/gradle-wrapper.properties and change gradle-1.6-bin.zip to gradle-2.4-bin.zip.

./gradle/wrapper/gradle-wrapper.properties :

#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip

It should compile without any error now.

Note: update version numbers with the most recent ones

Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
0

I used a local distribution of gradle downloaded from gradle website and used it in android studio.

It fixed the gradle build error.

Robert
  • 5,278
  • 43
  • 65
  • 115
Akhilendra Singh
  • 661
  • 11
  • 16