3

I created a new project in android studio and initial build couldn't finished. Build continues for a long time.image I waited for an hour and then exit. I already tried toggle gradle online/offline and connecting/disconnecting with Internet. For my other projects(which I made earlier) initial build is successful but when i add new layout/activity or anything else same thing happens(build continues without any error/warning). Looks like I'm stuck in infinite loop. Please suggest me a way to solve this issue.

  • As I had this problem last time, the proxy settings of Android Studio were the reason. Have a look at this post: https://stackoverflow.com/questions/29391421/android-studio-gradle-takes-too-long-to-build – memres Feb 12 '21 at 07:12
  • It would be helpful if you could provide gradle logs of what is happening, when the builds start hanging. Also pls try building from command line using your projects `gradlew` so we can understand if the issue is an Android Studio or a Gradle problem. – ymindstorm Feb 12 '21 at 09:43
  • @ymindstorm log is empty. Only [App Name] Build... [Time taken till now] is showing. –  Feb 12 '21 at 10:30
  • Have you tried building with --stacktrace or --debug? – ymindstorm Feb 12 '21 at 10:37
  • yes but nothing happened. https://i.stack.imgur.com/zVF71.png is the state when AS is opened. –  Feb 12 '21 at 10:57

1 Answers1

0

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:

Android Studio gradle takes too long to build
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.

Solution#5:

Go to File -> Invalidate cache & restart after that do a clean build

try updating android studio if it is not updated

Rohan Arora
  • 303
  • 2
  • 12