ChatGPT解决这个技术问题 Extra ChatGPT

How to fix Android Studio getting stuck executing Gradle tasks?

Android Studio (Beta) 0.8.6 gets stuck when I try to build/run the project, as well as clean it. It stays responsive, but the Gradle: Executing Tasks message doesn't disappear (longer than 20 minutes is when I give up) and the app never runs.

This is what I attempted:

Invalidate caches/restart

Force quit and restart

Remove it from Applications (on Mac) and re-download it from the official website.

https://i.stack.imgur.com/r70AL.png

Try this, quit Studio, open terminal, run ./gradlew tasks --debug
@bhargavg I tried that, it says -bash: ./gradlew: Permission denied
@bhargavg go to /path/to/sdk/tools and run sudo chmod 777 gradlew or sudo chmod 777 * and then run command again

E
Eric

Fixed it by going to Android Studio -> Preferences -> Gradle -> and ticking Offline work. Still have no idea what was wrong, but at least now it compiles.

Edit: In new Android Studio Versions the path is File -> Other Settings -> Default Settings -> Build-Excecution-Deployment -> Gradle


Still slow, almost one minute.
This answer should be updated. File->Settings->Build-Excecution-Deployment->Gradle is the right location.
unable to find gradle option anywhere - File->Settings->Build-Excecution-Deployment->Gradle and Android Studio -> Preferences -> Gradle
File->Settings->Build-Excecution-Deployment->BuildTools->Gradle
My issue was different, see my answer.
C
Community

The question seems old but in case anyone need it.

I have just faced this problem recently, after a fresh Ubuntu 14.04 installation. After google for a while with no luck i checked the terminal, it turned out that libz.so.1 is missing. So i installed it, worked like charm.

Installing instruction here: libz.so.1: cannot open shared object file


As of Jan 2016, this is the required solution. For the lazy ones who do not wish to visit the link : sudo apt-get install zlib1g:i386
After lots of experimentation, this worked. This is the working answer...thanks
What about Mac OS X? I have zlib and there's the same problem.
After trying many solutions for two days, finally this worked. Thanks a ton!
This worked on ubuntu 16.06 (installing lib32z1). The Gradle Console in android studio actually gave info that libz is missing, and it is a good place to check in case of gradle problems.
B
Biswajit Karmakar

Enable Offline Work from Setting

https://i.stack.imgur.com/FD306.png


This worked for me when I run my project for first time on updated Android Studio 2.2 Preview 1.
t
tir38

This can happen for lots of reasons. So instead of giving an exact fix, here are some steps to help isolate the cause.

Run the gradle command from command line. Does it still fail? $ ./gradlew myTask If so, re-run with debug flag. Any useful info? $ ./gradlew myTask --debug If it's just hanging, try getting a stack trace. Search the dump file for myTask $ jps -mv | grep Gradle <--- be sure to use capital "G" 2290 GradleDaemon 3.3 -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Xmx2304M -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant $ jstack -l 2290 >> dump.txt <--- your process ID will be different If it's only hanging when running Android Studio, generate thread dump for Android Studio read more here.


H
HsnVahedi

You have to add execution mode to the file: AndroidStudioProjects/YourProjectName/gradlew so that Android Studio can execute it. if you are on a linux machine use this command: chmod +x gradlew to run this command you may need to have administration privileges. in Ubuntu you can use sudo chmod +x gradlew to do that


A
Alex

In my case looks like gradle was missing 32 bit library on a 64 bit Ubuntu 16.04. Doing sudo apt-get install libstdc++6:i386 resolved the problem.


n
nurettin

This happened to me after adding google play api to dependencies{}. ./gradlew app:assembleDebug showed an error saying something like Dex ID limit reached use multi-dex. just as I was setting it up as described here, I decided to remove the dependency I recently added and the issue was gone.

Google also suggests using proguard as a technique to optimize the number of Dex IDs in the same document.


a
alizeyn

For GNU/Linux Users:

I copied the SDK from another storage to my home directory. Then I was getting stock gradle build running. The problem was the permissions of SDK files. Watch the gradle console log and if you see some permission denieded stuff, then do the following - give all the files executing permission by this command:

chmod -R +x /path/to/android-sdk


a
a.p.

After a lot of struggle and following all solutions posted above (and in similar posts) I finally found that the problem on my PC was the antivirus application. I disabled it and gradle refreshed and built fast, as it did before the problem started.

It looks like my antivirus recently started blocking gradle from updating/downloading necessary information from the Internet and that is what is causing the delays and eventually timeouts in loading and refreshing a project. Disabling the antivirus it corrects the problem, every time.


Same here. Struggled with the solutions from this post and nothing worked. Luckily, stumbled upon this answer. My company laptop has McAfee installed and I had to disable some of its processes for the Gradle to finish the build process.
J
Juan Pablo

I have centos 7 64 bits installed on a virtualbox 5.0.16 virtual machine and gradle version 2.10 with Android Studio 2.0

The log file of gradle is located at $HOME/.gradle/daemon/2.10 Log file: daemon-<some number>.out.log

By inspecting this log file I found out that libz.so.1 was not found by aapt.

Despite that command "locate libz.so.1" output was

/usr/lib64/libz.so
/usr/lib64/libz.so.1
/usr/lib64/libz.so.1.2.7

aapt was not able to find it.

In order to solve the issue I had to execute

yum install zlib.i686

After that Gradle started working as a charm. Good luck!


M
Marc

I had something similar.

When I ran gradle from the command like it would throw this exception

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDevDebugJavaWithJavac'.

after waiting at this line for like 25 minutes

:app:compileDevDebugJavaWithJavac

it turned out to have something to do with the android annotations I was using. I replaced the

@UiThread 

I was using with

activity.runOnUiThread(new Runnable(...

And it started to compile just fine. Its weird because I was using the @UiThread annotation in lots of other places in my code.


S
Sebastian Schneider

In my case, I was getting this error by the Gradle Builder (Android Studio 2.2, Windows 10)

java.lang.RuntimeException: Timed out while waiting for slave aapt process, try setting environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds

The solution was just to add the variable SLAVE_AAPT_TIMEOUT to my Windows environment, and set it to 30


F
Fabiano

I was with the same problem and solved setting variable SLAVE_AAPT_TIMEOUT in System Variables with the value 30.


P
Parker

I'm on Windows, and I had the same problem.

For me, the gradlew executable somehow got deleted, no idea how. I'm on the Canary, and I've had the issue before.

In the terminal window on Android Studio, type gradlew and it will redownload and install it if it's missing. (My old solution was a complete reinstall of Android Studio, so this is easier)


A
Alexey Ivakhin

I had the same problem, even with new standard projects (Ubuntu 16.04). The problem turned out to be in third-party dependencies of the Gradle. View the file: ~/.gradle/init.gradle It may contain additional dependencies, which the Gradle can not load. You can see what can not be loaded in the console: ./gradlew --debug


b
billjamesdev

If you use realm library and use RealmStudio or RealmBrowser to open file .realm, make sure you perform delete file .realm/lock and folder .realm.management.


Y
Yogesh Jangid

I think java.exe is the reason of this issue. Just manually kill this application and try. It really worked for me using Android studio 3.0.1.


0
0101100101

In my case it was stuck on mergeDebugResources because I accidentally had a double-escaped single-quote \\' in a string. Android Studio doesn't mark this as an error, but instead gets stuck building!