Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

android - 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.

question from:https://stackoverflow.com/questions/37063217/stuck-with-gradle-build-running

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 -> Buil 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...