Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck with Gradle Build Running

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.

like image 726
Arun George Avatar asked May 06 '16 02:05

Arun George


People also ask

Why does Gradle build take so long?

Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal.

What is Gradle build running?

Gradle is one of the most important files or extensions that are present in the Android Project. Gradle handles all the libraries and application IDs and many important components of any Android application.

How do I stop build Gradle?

Note that it requires you to have gradlew executable in the project directory (it's there by default when using Android Studio). After the installation you can find "Gradle Stop" button on Main Toolbar and inside Run Menu.


2 Answers

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.

like image 54
SkyWalker Avatar answered Sep 20 '22 03:09

SkyWalker


Changing buildToolsVersion was the solution for me.

like image 23
Mateusz Kaflowski Avatar answered Sep 21 '22 03:09

Mateusz Kaflowski