How to fix Android Studio getting stuck executing Gradle tasks?

南楼画角 提交于 2019-12-17 08:56:07

问题


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.


回答1:


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




回答2:


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




回答3:


Enable Offline Work from Setting




回答4:


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




回答5:


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.




回答6:


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.




回答7:


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




回答8:


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

  1. Run the gradle command from command line. Does it still fail?

    $ ./gradlew myTask

  2. If so, re-run with debug flag. Any useful info?

    $ ./gradlew myTask --debug

  3. 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
    
  4. If it's only hanging when running Android Studio, generate thread dump for Android Studio read more here.




回答9:


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.




回答10:


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!




回答11:


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.




回答12:


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




回答13:


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




回答14:


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)




回答15:


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




回答16:


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.




回答17:


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.




回答18:


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!



来源:https://stackoverflow.com/questions/25629368/how-to-fix-android-studio-getting-stuck-executing-gradle-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!