Stuck at refreshing gradle project. What is happening under the hood? - java

I can not build any android project in Android Studio. Recently Android studio was updated to 2.3 as well as the gradle version. I think somewhere the update has messed up I am not sure where it is. I have deleted .gradle directory from the home folder several times by now. Changed the distributionUrl to older version of gradle. But the problem persists. Where to look at what is going on? How to solve this issue?

The reason behind taking too much time on refreshing gradle project is, it was downloading gradle distribution and each time and for some network issue the download was never being completed. The zip file for gradle distribution was 91MB. So the network error + slow internet connection made it impossible task for my Android Studio.
I found two solution for this:
First approach is we have to download the gradle distribution manually from services.gradle.org/distributions. Then follow the process of this answer of the question - Android Studio Stuck at Gradle Download on create new project.
Second approach is somewhat like the first approach but less complex. Download gradle distribution. Extract it somewhere. Then go to:
File > Settings > Build, Execution and Deployment > Gradle
Check Use local gradle distribution. Set the Gradle home to the folder we have extracted.

I had the same problem
What I have done is
1.Close your project
2.Delete folders of .idea , .gradle, gradle folders from my project(not from home). then
3.File=>open your project
press ok in the dialogue box it will automatically set the gradle for you.
or
You can specify gradle path
settings->build excecution deployment->build tools->gradle set your
gradle home path to your downloaded gradle

I faced this case because of slow internet, Each time while beginning with the project, it downloads the gradles taking more time.Finally refreshing complete after waiting for 10 minute.

Related

Gradle on Intellij not syncing

Hope you guys are having a nice day!
I am currently working on a project which uses an Older version of Gradle, specifically Gradle 3.0. Hence, I installed the older version and in Intellij set it as the source in Gradle Settings. However, after that was done, I clicked build and it immediately started downloading index files. And as soon as it was done downloading it brought up the following error code:
Unable to find method 'org.gradle.api.invocation.Gradle.getIncludedBuilds()Ljava/util/Collection;'
org.gradle.api.invocation.Gradle.getIncludedBuilds()Ljava/util/Collection;
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I then went on to Re-Download as it advices, and similarly restart but after building the project again, it gives the same error.
I really don't know where I am going wrong. I have attached an image of what my gradle settings look like and an image of my IDE.
Also out of curiosity, as you can see in the images, in the project directory: There are so many gradle version, what could those mean? It went from 2.14 to 7.5.1 like automatically? I have no idea why.
Any help would be greatly appreciated!! Thank you Again!
The getIncludedBuilds method is supported only since Gradle 3.1 version as documentation shows.
You can try to invalidate caches and restart option on intellij
try File->Invalidate Caches from your IDE or you can Delete .idea file from your src folder and run the project again.

IntelliJ : Cannot resolve method 'run(java.lang.Class, String[])'

I've encountered a problem where on all of my applications, there's a red cross on the top right. I can run it, but the cross doesn't seem to go away.
I've opened the run/debug configurations and it says Warning : Main method not found. I don't understand why it's not found when I already have a corresponding main class and method for each and every application.
I tried to close the project, restarting IntelliJ, restarting my laptop, refreshing my desktop, refresh Gradle by clicking Reimport All Gradle Projects, rebuild the project and clicking Invalidate Caches / Restart. I also tried other suggestions I found on StackOverflow such as deleting the .idea folder. Nothing. The red cross still shows up. I've also realized that I do not have the out folder in all of my Applications.
I just set the language level to equal my SDK version at Project Structure. Finally, it is disappeared.
In Project Settings, First make sure SDK path is correct. Preferably install and use your own SDK. Then use the same SDK in Project and Modules in Project Settings.
File->Project structure ->SDKs
Choose JDK home path, if no jdk is in the path,
you'll see an icon download jdk
download then ok
Try to copy src and gradle folders and buil.gradle and settings,gradle files in separate folder. Then open this new folder as new project in intellij. Then intellij will propose Import as gradle project... - push it.
If problem remained see you build.gradle

Executing Gradle without a settings file has been deprecated : How to write a setting file and where to save

hello friends i am new to android studio(ver :3.6.1) and gradle(ver:6.0.3) i have just somehow installed it (means my gradle was not installing or taking time so i manually installed files in chrome and placed it in folder and everything is okay but due to version upgrade i am facing this issue) and when i used to sync it , it shows me error that the Deprecated Gradle features were used in this build, making it incompatible with
Gradle 7.0.Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings then i did same build with --warning-mode all and i got this message --Executing Gradle tasks as part of an undefined build has been deprecated. This will fail with an error in Gradle 7.0. Consult the upgrading guide for further in
formation: https://docs.gradle.org/6.3/userguide/upgrading_version_5.html#executing_gradle_without_a_settings_file_has_been_deprecated
afterthat i went to the given link and then i found this
Have A look to Image
i don't know how to write the setting.gradle or setting.gradle.kts file and where to save it i once tries to save it in my gradle home folder but it gave me another error that the method i used to do so is not known i have attached my gradle project build log screenshots
have a look to image
thank u i hope u will help me please give me suggestions and help me to do it 😞😞
No need to hurry - as long as you don't upgrade to Gradle 7.0 nothing bad will happen. And since Gradle 6.3 has been released quite recently the next release is at least 5 to 6 weeks away...
If your project is a simple project without subprojects, the settings.gradle file can be an empty file (though it needs to exist).
You must place it into the same directory as your build.gradle file.
You need more content in the settings.gradle file if you start creating multi-project builds. The documentation about multi-project builds is part of the gradle documentation (what a surpise!): https://guides.gradle.org/creating-multi-project-builds/
Detailed information about the allowed settings are available at https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html

Unexpected lock protocol found in lock file. Expected 3 found 0

In android studio I keep getting this error message when building.
I've tried
deleting the .gradle file multiple times and restarting the IDE but the error doesn't seem to stop.
I made sure that I've updated EVERYTHING there is in SDK's and other things it required.
I've tried several solution -
First Solution: Go to File -> Invalid Chaches/Restart...
Second Solution: First, Build -> Clean Project and the Build -> Rebuild Project
Third Solution: First close the project and remove from workspace of Android Studio, then Go to C:\Users\user.gradle then delete .gradle folder. After that Open the project again.
But none of them worked! Then i got a solution, which worked in my case, the solution is bellow -
In my case, the problem was in gradle version. Check your Gradle version File -> Project Structure(Ctrl+Alt+Shift+S) and Plugin version also.
Delete the XXX.Lock file, and rerun the project. You should be able to find the location of this .lock file in the error message
is solved mine by downloading the latest version the latest version of gradle distribution.
https://services.gradle.org/distributions/

How to Setup gradle-2.2.1-all.zip Manually

I want to run my unit test with this command
gradlew.bat connectedInstrumentTest
But it tries to download https://services.gradle.org/distributions/gradle-2.2.1-all.zip
And my corporal network blocks it. Hence, I want to setup the zip manually, I already downloaded it from browser.
The ways I failed are listed below
Pasting it in Program Files\Android\Android Studio\gradle\
gradle-2.2.1 didn't work
File -> Settings -> Build execution, Deployment -> Build Tools and
defining the gradle home directory didn't work
Any suggestions except these will be much appreciated. Thanks.
Solution :
1). Delete the C:\Users\username\.gradle folder
2). Download http://downloads.gradle.org/distributions/gradle-2.2.1-all.zip
3). Create a new project in android studio.
4). When this time it stucks at gradle building, Force close the android studio.
5) Now go to C:\Users\username\.gradle\wrapper\dists\gradle-2.2.1-all\c64ydeuardnfqctvr1gm30w53 (the end directory name may be different)
6) Delete gradle-2.2.1-all.zip.lck and other files from this directory.
7) Paste the new downloaded gradle-2.2.1-all.zip here.
8) Run the android studio. :)
In your command you're using the Gradle Wrapper. The Gradle wrapper is a thin wrapper around the real Gradle bin. It's intended to be checked in to your source control and it then downloads the version of Gradle you've defined in gradle/wrapper/gradle-wrapper.properties. The advantage here is the version of Gradle used in the build is directly tied to the source control.
You have 2 options:
use the gradle command instead of gradlew - this will use the gradle that's installed on the local machine (assumes that 'gradle' is on the PATH). The drawback here is you have to have installed Gradle somewhere before the build will work.
change distributionUrl in gradle/wrapper/gradle-wrapper.properties to point to a different URL and host that file yourself somewhere. You get all the advantages of the wrapper but fix the problems you're having downloading it.
Mostly, this error occurs due to brake in internet or slow connection network.
A gradle file downloads partially, this zip file isn't extractable and neither does re-download using Android Studio work.
So, to solve this problem, you have to:
Delete the gradle download folder or download the gradle zip file manually and configure using the following method
Download requires gradle and past the zip into C:\Users\your_pc_name\.gradle\wrapper\dists
Finally, open Android Studio and run the project.
The gradle version care fully before downloading

Categories