Stuck with Gradle Build Running - android

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.

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

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.

Changing buildToolsVersion was the solution for me.

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.

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

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.

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.

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.

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

Related

Android studio 2.3 refreshing gradle project taking forever

I updated my android studio to the new version 2.3 and was asked to convert my project to match the new formats which I did. I was asked to update the gradle version too and I did. Now one eternity later it's still refreshing my project gradle. I've restarted it several times and I have active internet connection. Any suggestions
This method works for Me :
Change Gradle Home Path as C:\Program Files\Android\Android Studio\gradle\gradle-3.2
To Open Gradle Home Setting :
Settings->Build,Execution,Deployment->Gradle->Gradle Home
It depends sometimes on what are you building. As Hamid said, it´s a must do working Offline, it greatly reduces times, or at least it did not that long ago.
Also checkout that you are not building google APIs that you are not using, be careful with google's play-services or maps, they sometimes take a bunch of time and maybe you are not using them.
If that's an option, install Android Studio in a SSD, don't buy one, but if you have it, consider moving it, it reduced my gradle about 90%.
Also, check this, a bit old, but may help.
Could be caused by Microsoft Defender.
Check if msmpeng.exe is running in task manager
and exclude Android directory.
using default gradle wrapper and disconnecting from my corporate network to a 4G network solved my problem
File> Settings> Build, Execution, Deployment> Gradle> and check the Offline work
If you have an failed for sync gradle. Such as; Gradle sync failed: Minimum supported Gradle version is 3.3. Current version is 3.2.
Download Gradle supported version manually.
Uncheck "Use default gradle wrapper (recommended)"
Check "Use local gradle distribution" and set Gradle home path.
Check offline work.
Updating the gradle path in
File > Settings > Build, Execution, Deployment > Gradle
worked for me. The problem occured after updating Android Studio.

Android Studio 2.2 preview1 errors

So i'm trying to use Android Studio 2.2 preview-1 in Ubuntu 14.04 LTS.
I'm using gradle-2.10 and gradle-plugin 2.2.0-alpha1 along with openJDK-8.
compileSdkVersion 23
buildToolsVersion "23.0.3"
First the studio.sh didn't run and i found the solution to change #!/bin/sh to #!/bin/bash. Voila --it starts properly.
But in build.gradle files, warning is shown--
'dependencies' cannot be applied to '(groovy.lang.Closure)'
and its not finding imported class from library project(includes a jar only).
Please someone help me out.
The only fix that I found for this is, every time I open a project, I go to Settings>Build, Execution, Deployment>Gradle, change to "use local gradle distribution", click apply then click "use default gradle wrapper" and ok.
This should fix, but its quite annoying to do this everytime.
It Looks like a problem of version 2.10 of the wrapper version on gradle.
After reading around people's workaround like
"invalidate cache and restart"
delete .gradle file in the project and re-open it
etc etc
I just try for fun to install a standalone version of gradle since I'd always used only the wrapper version that cames with android studio.
And with it there is any error and any warning.
For anyone who wanna try (I'm a mac's user):
install gradle (by homebrew is fine and pretty easy) brew install gradle
tell to AS to use that one instead the wrapper version preference -> build, Execution, Deveployment -> Gradle -> use local gradle distribution
if you install it by homebrew like me the correct path will be: /usr/local/Cellar/gradle/x.yy/libexec
where x.yy it suppose to be 2.11 (that is the last version provide by brew even if the lastest version released is 2.13)
I've realised just now that the steps above doens't fix the definitly. Each time you re-open the project the problem came again and again.
It's annoying but changing betwen use of "wrapper"/"regular gradle" take the warning away.
But this means also that isn't a problem o the gradle as I'd assumed at the beginning.
...let's wait a permanent fix ^^
This issue is fixed in Android Studio 2.2 preview 2 (download from this page).
Disabled a couple of Groovy inspections that reported incorrect errors in build.gradle files
From the changelog.

Gradle is failing on syncing my project in the new Android Studio 2.0

I have just upgraded (i.e., installed a full new version) my Android Studio from 1.5 to 2.0. The upgrade seemed to go smoothly, but I am having trouble with my project when I open it, when Gradle is syncing my project.
After Gradle sync runs for a couple of minutes I get this error:
Failed to sync Gradle project MyProject
Unknown host 'jcenter.bintray.com'. You may need to adjust the proxy settings in Gradle.
Error: Enable Gradle "offline mode' and sync project
Learn about configuring HTTP proxies in Gradle
So, I click on the link that says:
Enable Gradle "offline mode' and sync project
Then Gradle spins for a second or two, and I now have this message:
Failed to sync Gradle project MyProject
Error: No cached version of com.android.tools.build:gradle:1.3.0 available for offline mode.
Disable Gradle 'offline mode' and sync project
So, I click on this link:
Disable Gradle 'offline mode' and sync project
And I am back to my first error again.
The machine I am working on is 100% off line. It does not have, nor will it ever have any kind of network connection whatsoever. I figure I need to disable some kind of check that requires the internet, but I am not sure what. Is this fixable, or do I have to downgrade back to Android Studio 1.5?
UPDATE
I am also getting this error message:
Gradle sync failed: Unknown host 'services.gradle.org'. You may need to adjust the proxy settings in Gradle.
Ok, I fixed my issue so I wanted to post how I did it in case somebody else runs into this situation.
I was googling around and found a statement regarding working offline with Android Studio that read:
You can, however you won't be able to use any Gradle dependency. Gradle search into the repositories for dependencies using internet, so if you're completely unable to work online. Try not to include anything in the Gradle files, if you do, you'll have to sync it and it'll fail. Bascially just don't touch Gradle files and you'll be good to go.
So, I looked at my gradle files, specifically the build.gradle for the Project (not for the Module). Once there, I noticed a line:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
So, I replaced 1.3.0 with 2.0.0 and the project built just fine.
I hope this helps somebody else in the future. Good luck.
I got same problem when I downloaded "BackboneExampleApp" source code from guithub Click Here For Code. I have done following process by watching settings of my old projects and found these errors. I resolved both errors, run my app and got errors to upgrade project and finally when I updated then no more problems exist. Just see pictures for help.
build.gradle (Project:BackboneExampleApp-master)-->
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
I also come with the same problem in my application. I have Done invalidate caches/restart then the problem is resolved.
I had the same problem as yours. Fortunately, I managed to solve it. You need to go to File >> Settings >> Build, Execution, Deployment >> Build Tools >> Gradle. You need to change the Gradle Home. Mine was "C:/Program Files/Android/Android Studio/gradle/gradle-2.08" and it said the path is invalid. So, just recheck your path in your file explorer and change it. I changed mine to "C:/Program Files/Android/Android Studio/gradle/gradle-2.10".
I had a similar problem. I was trying to build one of the media samples. I tried to use gradle 2.0.0 as you suggested but it didn't work. Got me on the right track though. gradle 2.1.0, along with deactivating offline mode got it to work.
For me it was a connection issue, that I have checked my connection is working in the same second I have enabled and disabled offline Gradle, then Android Studio download the needed files
NB: My Connection was disconnecting and reconnecting many times, so i figured out that this error was caused by the connection specially it was not the same time it takes when trying to sync my Gradle
For those have issues with error message: Learn to configure HTTP settings, below is the solution that worked for me. Am using Android studio 2.3.3:
Go to http://developer.android.com/studio/intro/studio-config.html
Step 1: Follow the instructions on: Set up Android studio proxy.
Step 2: Follow the instructions on : Android plugin for gradle HTTP proxy setting. You will see proxy settings under : # project wide gradle settings, copy the code there and paste it into the empty space in gradle properties file which is under the build gradle in Android studio. Make sure you are connected to internet while on this process. Wait until the the error disappears.
Step 3: you may see another message pop up stating: some folders may have been missing syn now. Just click on syn now.
I hope this help, thanks all.
I was fallen the same trouble, you mentioned. But I solved it myself. I connected my pc to the internet and rebulit the project using PROJECT>>REBUILT PROJECT.
Then some downloads could be seen below with the name of jcenter.......
THEN THE PROBLEM SOLVED...😃
Gradle build became successful..
I faced the same issue. Make sure that you have made an entry in path in environment variable for gradle
C:\Program Files\Android\Android Studio\gradle\gradle-3.2\bin
After disable offline mode and setting the path in environment variables, the issue was fixed and Gradle was build cleanly.
It seems there are multiple reasons for this issue. I fixed it by changing the "Gradle version" and "Android plugin version".
It might be helpful to someone. Go to File->Project Structure. Select Project and update your gradle and android plugin versions.
I also came with the same problem in my application..The application Gradle version is 2.3.3 .I just update the Gradle to 3.0.1 .and the problem is solved.
My problem was different from all answers; gradle distribution url was wrong..
It might be the problem that distributionUrl can be wrong in gradle-wrapper.properties file.

Android Studio starts downloading gradle

I have downloaded android studio and sdk and everything required but when I start a new project studio starts downloading gradle which is already downloaded with android studio. If I try to stop that download, it can't be stopped, I need to shutdown my laptop.
Please tell me why this happens!
And if I import any project then it shows a message that gradle build failed and tells me to install build tools API Level 7 which NOBODY uses now a days. What's wrong with this studio??
I am using Ubuntu 14.04, .gradle directory of my home folder has files of more than 300 Mb I don't understand what this android studio keeps downloading.
Please help me fixing this problem
That is normal one time download of maven gradle dependencies and packages. However it usually takes a long time to download and build. Not sure what are the reasons for this.
Android studio contains gradle essentials, but for some reasons that is insufficient to run command line tools.
There is a workaround to skip this download by adding gradle repo directory to android studio settings (Configure --> Settings --> Gradle). You have to manually add GRADLE_HOME to the system PATH variable according to your operating system. Run gradle-v in command line to confirm everything works right.

Error in android studio while creating new project [duplicate]

When I try to build a project on Android Studio, I get this error:
Compilation completed with 1 error and 0 warnings in 9 sec
1 error
0 warnings
org.gradle.tooling.GradleConnectionException: Could not install Gradle distribution from 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.: Could not install Gradle distribution from 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
What can I do to fix it?
UPDATE:
When I look at the Error Log, I saw this:
org.jetbrains.plugins.gradle.settings.GradleSettings cannot be cast to org.jetbrains.plugins.gradle.settings.GradleSettings:
org.jetbrains.plugins.gradle.settings.GradleSettings cannot be cast to org.jetbrains.plugins.gradle.settings.GradleSettings
Please read the log from:
On Microsoft Windows:
[Windwos Drive]\Documents and Settings\[your username]\.AndroidStudioPreview\system\log
On Mac and Linux: ~/.AndroidStudioPreview/system/log/
And you will find the tmp download path of gradle-1.6-bin.zip. For example, mine is:
2013-05-17 09:42:16,934 [ 283002] INFO - ution.rmi.RemoteProcessSupport - Unzipping C:\Documents and Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok\gradle-1.6-bin.zip to C:\Documents and Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok
...
Caused by: com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not install Gradle distribution from 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
java.util.zip.ZipException: error in opening zip file
So I know the cause: I downloaded an incomplete ZIP package.
Then I downloaded the full ZIP package from http://services.gradle.org/distributions/gradle-1.6-bin.zip manually and copied this ZIP package to:
Windows: C:\Documents and
Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok\
Mac OS X: ~/.gradle/wrapper/dists/gradle-1.10-all/6vpvhqu0efs1fqmqr2decq1v12/
Everything is OK now.
For OS X:
Install Homebrew as a package manager. Then on Terminal, run:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Install Gradle:
brew install gradle
It is the easiest way to get Gradle.
Before you click to new project, go to configure and set your proxy. I recommend set host name and port number, since I had problems with auto-detect proxy settings. Check your connection in settings.
I also had issues downloading Gradle through Android Studio.
This was my workaround:
Download Gradle directly from http://services.gradle.org/distributions/gradle-1.6-bin.zip
Copy the contents of gradle-1.6 to \Android\android-studio\plugins\gradle
Copy gradle.jar to \Android\android-studio\lib\
Restart Android Studio
Hope this helps!
Edit the gradle wrapper settings in gradle/wrapper/gradle-wrapper.properties and change gradle-1.6-bin.zip to gradle-1.8-bin.zip.
./gradle/wrapper/gradle-wrapper.properties :
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
It should compile without any error now.
In my case this was because the system had low memory. When I closed some applications, the error disappeared.
For me it turned out to be my firewall, which is VIPRE, was blocking the Gradle.org site and quietly causing a bad gradle-1.7-bin.zip to be created under .gradle\wrapper\dists\.
I had to open VIPRE and add gradle.org to "Bad Web Site Exceptions" (menu File -> Settings -> Firewall).
Then I downloaded http://services.gradle.org/distributions/gradle-1.7-bin.zip using a browser and overwrote the bad version. I restarted Android Studio, and all is good.
FYI, on my Mac, it was downloading Gradle into the ~/.gradle directory. You can see how it's progressing by looking there:
du ~/.gradle
I noticed that my MyProject/gradle/wrapper/gradle-wrapper.properties file was completely empty, so I deleted it and Android Studio proceeded to download whatever it needed.
After that it worked.
I tried Kiki Hu's solution, and it worked. After that, there will be more downloads from the Maven repository which includes Dalvik Debug Monitor Server (DDMS), Guava, etc., which again is not required if you are exporting from Eclipse into Android Studio.
If you're like me, you tried to start a version prior to 0.2.0. Following Google's notes
in Getting Started with Android Studio, you'll need to remove and re-install Android Studio.
"Note: There is not a patch update available from 0.1.9 to 0.2. To update from Android Studio 0.1.x to 0.2.x, you must install a new Android Studio bundle from this page. The reason for that is that we have made changes to the bundled SDK such that it includes a pre-configured local Maven repository which can serve up the v4 support library and which is required for creating new projects."
Also be aware that if you have your Android SDK files stored in C:\Program Files (x86)\Android\android-studio\sdk you should move them before the uninstall, or you'll need to download the SDK files again.
After the un-install and re-install, it is now working on my Windows 7 64-bit system.
Remove all files from C:\Documents and Settings\[User]\.gradle\wrapper\dists\, rebuild the project and rebuild your project on Android Studio. It works for me :)
I have noticed one thing: When my Android Studio is build 130.737825, it automatic downloads Gradle 1.6 to C:\Users\yourname\.gradle/wrapper/dists/gradle-1.6-bin/72srdo3a5eb3bic159kar72vok/.
However, when I update my Android Studio to build 132.821530, it automatically downloads Gradle 1.7 to C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.7-bin\2g3i7gan25uopmtc0lnjb1l9ff.
I don't know if it matters.
I had this error under fresh installation of IntelliJ (14.0), the problem was that I had not specified JDK. Fix: press ctrl + A + S (project structure), and check if SDK is correct.
my error looked like this:
Error:Android Gradle Build Target: org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle installation ...

Categories

Resources