54

While trying to build my Application on Android Studio 2.1 (On Ubuntu 16.04), it gets stuck on the below note:

Executing tasks: [:app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources]

Can anybody please help me out.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
Arun George
  • 1,167
  • 3
  • 15
  • 29
  • while my problem wasn't exactly the same (i had an endless "Starting gradle daemon..." loop), [this](https://stackoverflow.com/a/64844390/3438172) fixed it for me. – Ace Nov 15 '20 at 12:34

9 Answers9

100

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.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • 3
    I think, 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. Thanks:) – Arun George May 08 '16 at 18:45
  • org.gradle.parallel=true should be used only with decoupled projects (IE: project that don't share objects). You can read more here: https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:decoupled_projects – qwlice Sep 27 '16 at 07:54
  • i have same probelm http://stackoverflow.com/questions/41502164/android-studio-2-2-3-gradle-build-running-stuck – Aditya Vyas-Lakhan Jan 06 '17 at 09:11
  • 3
    Solution 1 makes builds finish 20 times faster for me! – Swindler Feb 14 '17 at 22:06
  • In Solution-1 is this a text file that you save as "gradle.properties"? – 101is5 Dec 08 '21 at 18:32
7

Changing buildToolsVersion was the solution for me.

Mateusz Kaflowski
  • 2,221
  • 1
  • 29
  • 35
  • This is the real solution. And sometimes the problem isn't caught by the warnings we so often see in the build.gradle file. Thanks! – SMBiggs Oct 06 '20 at 19:24
  • Elaborating: click the Project tab (upper-left corner)> right-click the "app" folder> click "Open Module Settings" > Modules > Properties > Select a version for "Compile SDK Version" and a version for "Build Tools Version" . Source: https://www.py4u.net/discuss/646549 Anyone tried selecting a version only for "Build Tools Version"? – 101is5 Dec 08 '21 at 18:15
7

The issue is that the project isn't synced with the gradle files. The resolution I did was go to File > Sync Project with Gradle Files and it was able to sync.

Daniel Mendoza
  • 487
  • 4
  • 6
4

I have tried all solution. Nothing has worked. So I just restarted my PC and its working fine. You can try it.

sum20156
  • 646
  • 1
  • 7
  • 19
3

For my case I had to install gcc-multilib

$ sudo apt-get install gcc-multilib

Check the Gradle Console at the bottom right as it has more output than the Event log.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
N Jacobs
  • 341
  • 2
  • 16
1

You're probably behind the proxy, you might have recently changed your password or something has changed. Go to

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

in gradle.properties file, delete/ change proxy settings. They are different to your android studio proxy settings.

Had the same issue, gradle used to take an hour to build. After I deleted proxy settings from gragle.properties file, it now takes couple seconds.

Sebastian
  • 1,321
  • 9
  • 21
TSlegaitis
  • 1,231
  • 15
  • 29
  • This worked for me. It turns out that even though I set the proxy to No Proxy in Android Studio, the gradle.proerties file still contains Proxy entries. – F0r3v3r-A-N00b Jan 04 '20 at 14:39
  • I can't find gradle.properties. Is it supposed to be in the .gradle folder, inside any subfolder or do I have to create it? If I have to create it, how can I do it? – 101is5 Dec 08 '21 at 19:05
0

Adding more to @SkyWalker's answer:

Also check if you have the latest version of gradle. Updating gradle plug-in to the latest version could help.

Note: I have a similar setup(Android Studio 2.1 on Ubuntu 16.04), and I had a similar problem. Updating gradle to the latest version solved the problem for me.

Community
  • 1
  • 1
jayeshsolanki93
  • 2,096
  • 1
  • 20
  • 37
0

Resolution for Gradle stuck using Android Studio version 4.2.2:

When the resources are downloaded successfully the Android Studio should be restarted with "Invalidate cache and restart" and offline Gradle mode should be activated before platform-tools indexing.

Aydın Ahmed
  • 559
  • 5
  • 11
0

May be it's bad way, but start studio with sudo nice --17 IDE name seems worked for me