How to Fix Android Studio Getting Stuck Executing Gradle Tasks

How to fix Android Studio getting stuck executing Gradle tasks?

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

Android Studio 2.2.3 Gradle Build Running Stuck

If you are behind a proxy, create a gradle.properties file next to your build.gradle file with this :

systemProp.http.proxyHost=YOUR_PROXY
systemProp.http.proxyPort=YOUR_PORT
systemProp.http.proxyUser=USERNAME
systemProp.http.proxyPassword=PASSWORD

systemProp.https.proxyHost=YOUR_PROXY
systemProp.https.proxyPort=YOUR_PORT
systemProp.https.proxyUser=USERNAME
systemProp.https.proxyPassword=PASSWORD

systemProp.http[s].proxyUser and systemProp.http[s].proxyPassword are not required if you don't need to login for your proxy. In such a case, remove these lines.

Gradle Build gets stuck at Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources]

I managed to solve the problem after a lot of trial and error.

  • Firstly I changed the build-tools version to 22.0.1. I know this is an outdated version, but it worked for me.
  • After that, Gradle build finished with an aapt error, for which I installed the following.

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

These solved the problem for me.

Stuck with Gradle Build Running

Actually it is not stuck. It takes more time to build. I have got almost 3 solutions that can fix the issue.

Solution-1:

Following the steps will make it 10 times faster and reduce build time 90%

First create a file named gradle.properties in the following directory:

/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)

Add this line to the file:

org.gradle.daemon=true

org.gradle.parallel=true


Solution-2:

If Android Studio has a proxy server setting and can't reach the server then it takes a long time to build, probably its trying to reach the proxy server and waiting for a timeout. When I removed the proxy server setting its working fine.

In Android Studio go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle

Check the 'Offline work' under 'Global Gradle settings'

It will reduce 90% gradle build time.



Solution-3

If you are using Google Play services, make sure you aren't using this in your Gradle build script:

compile 'com.google.android.gms:play-services:8.3.0'

Only use those Google APIs that your app is really using. If all you are using is Google Maps, you would use this:

com.google.android.gms:play-services-maps:8.3.0

When I did this, my compile time went from over 2 minutes to around 25 seconds. For a list of the Google apis that you can selectively compile against, see:

https://developers.google.com/android/guides/setup

Resource Link:

  1. Android Studio gradle takes too long to build
  2. Discussion about stuck in gradle build

Solution#4:

Arun George has commented the following solution.

the issue was due to certain 32 bit libraries missing. Had to do sudo apt-get install lib32z1. Adding to gradle.properties helped reduce
the build time.

Android Studio startup stuck in gradle running

I don't use ubuntu or know the answer but these links seem to be dealing with the same issue:

1) How to fix Android Studio getting stuck executing Gradle tasks?

The solution to this one was to install libz.so.1 and you can find installation instructions here: libz.so.1: cannot open shared object file

2) I can't build project in Android Studio on Ubuntu. Gradle running build takes infinity

The solution to the second one was to use these two commands in Terminal:

sudo dpkg --add-architecture i386

sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386

3) Android Studio gradle takes too long to build

I'm not sure the third link is as relevant, as it solves the problem of gradle builds taking a long time, not the problem of gradle builds getting stuck, but it still may be helpful information.

The solution to the third link was to go to:

In Android Studio go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle

Check the 'Offline work' under 'Global Gradle settings'

http://i.stack.imgur.com/vX0Or.png

Flutter App stuck at Running Gradle task 'assembleDebug'...

In my case, Windows Firewall was causing this problem. After I disabled it temporarily the problem was gone. Worth giving it a try. Good luck!



Related Topics



Leave a reply



Submit