Android Studio Gradle Download Error - android

When I load Android Studio, I get an error
Gradle 'HelloWorld' project refresh failed
Error:Could not download artifact 'com.android.tools.build:builder-model:0.12.1:builder- model.jar': No cached version available for offline mode
Not only this but Android Studio takes a long time to load a project; stuck on Gradle Resolve Dependencies.
I am on Windows 8.1 and using JDK 8
How would I fix this?

You probably have Android Studio configured to use Gradle in offline mode, and it's failing because it lacks dependencies that it needs to download. Make sure your computer has internet connectivity, and in Preferences > Gradle > Offline work, make sure that setting is unchecked.

For Android Studio 3.3.2 -
Open File > Settings > Gradle > (unchecked) offline work on Global Gradle Setting.
Make sure that you have internet connection and try to sync your project more (or File > Sync project with gradle files).

the simplest solution is -
click file > project structure > Gradle Setting >
now check if your "Gradle user Home" field is empty if it is . then enter the path of your gradle.
your gradle should be stored in
C > users > .gradle
copy the path and enter it here and now click on gradle build button on top right in your android studio.

Related

Sync project in android studio failed

I'm totally new in android programming and by now just trying to run a "Hello World" program! But I couldn't! This is what I've done till now:
Previously I had android-studio-ide-171.4443003-windows installed on my laptop, and I installed all SDK Tools from SDK manager. But every time I wanted to sync a project it end up with this error:
ERROR: Could not find com.android.tools.build:gradle:3.5.0. Searched
in the following locations:
- file:/C:/Users/Pro/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- file:/C:/Users/Pro/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- file:/C:/Users/Pro/.android/manual-offline-m2/gmaven_stable/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- file:/C:/Users/Pro/.android/manual-offline-m2/gmaven_stable/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
Required by:
project : Open File
then I updated my android studio to android-studio-ide-191.5791312-windows32, and again it get that error! so I download android-gradle-plugin-3.5.0-beta01 and gmaven_stable from android developer site and as the site said, I extracted them and copy the content into [my home directory]\.android\manual-offline-m2. and then restart android studio, but the problem still exist!
Then I went to Settings > Build, Execution, Deployment > Gradle and checked the "Offline work" and specified the "Service directory path" as "[my home directory]/.android/manual-offline-m2/android-gradle-plugin-3.5.0-beta01" and again tried to sync the project, but sync got new error:
ERROR: No cached version of com.android.tools.build:gradle:3.5.0 available
for offline mode.
now I'm totally confused and don't know what should I do to solve this problem! If anybody help me I will really appreciate that.
Open android studio go to your project -> build.gradle -> edit this code
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
Try lowering your build.gradle version to classpath 'com.android.tools.build:gradle:3.4.2'
I think your android studio does not support that kind of classpath version.

could not download httpclient.jar each time I press Try again

10:37 PM Gradle sync started
10:37 PM Gradle sync failed: Could not download httpclient.jar
(org.apache.httpcomponents:httpclient:4.5.2): No cached version available
for offline mode
Consult IDE log for more details (Help | Show Log) (642 ms)
How to fix this bug?
Be sure to have configured a remote repository where the component is available. In this case https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient.
Gradle depends on the maven repository. You can define additional repositories either in your gradle script or globally in ${user.home}/.m2/settings.xml.
This error comes when grade version is upgraded (as part of studio upgrade or stand alone). Check latest version and select that as part of settings here.
1- In Android Studio go to File > Settings > Build, Execution, Deployment > Gradle > Use local gradle distribution > then choose the latest version shown or new file (that you might have downloaded and unzip it) from your computer
2- Click Ok
3- Inside "build.gradle(Module:app)" make sure that compileSdkVersion and targetSdkVersion are same
8- Click Sync Now

Configuration on demand is not supported by the current version of the Android Gradle plugin

After upgrading to Android Studio 3.1.2 I am getting the following error:
Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org.gradle.configureondemand=false in your gradle.properties file or use a Gradle version less than 4.6.
I attempted following the suggestion but this did not fix the issue. Any ideas? All help is greatly appreciated, thank you.
No need to downgrade!
Disabling configure on demand requires two steps:
Remove org.gradle.configureondemand from gradle.properties.
In Android Studio,
For Mac go to the Preferences > Build, Execution, Deployment > Compiler and uncheck the configure on demand.
For Linux/Windows go to the File > Settings > Build, Execution, Deployment > Compiler and uncheck the configure on demand.
Note, there are 2 gradle.properties files
In your project gradle.properties
${HOME}/.gradle/gradle.properties
In Android Studio, just go to File -> Settings -> Build, Execution, Deployment -> Compiler and click to uncheck the configure on demand option, then click Ok and Sync Project with gradle files again.
I get same error after update to AS 3.1.2.
You can still use Gradle version 4.6 but downgrade Android gradle plugin to 3.1.1
EDIT:
just invalidate cache and restart
It is already known bug in Android studio even in the Documentation, They have mentioned about this Problem.
The easiest way right now is to disable this feature by going
Open the Preferences window by clicking File > Settings (on Mac, Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment > Compiler.
Un check the Configure on demand checkbox.
Click Apply or OK.
Check this Image for warning they have provided for specific Gradle plugin versions.
Other 'solution' is use the suggestion by Android Studio. Plugin Android Gradle 3.1.3 and Gradle version 4.4.
From Android Studio uncheck the configure on demand:
Follow below steps:
For Mac go to the Preferences > Build, Execution, Deployment > Compiler and uncheck the configure on demand.
For Linux/Windows go to the File > Settings > Build, Execution, Deployment > Compiler and uncheck the configure on demand.
Now sync your project
Happy coding! :)
The #wookupmaker answer is correct. But, if it still doesn't work, the problem migh be a global gradle.properties.
Even if I tried to override
org.gradle.configureondemand=false
in my local(project specific) gradle.properties, somehow it did not work.
After editing global (~/.gradle/gradle.properties) it worked as expected
Just you need to update Android Gradle Plugin update to 3.2.0-alpha16.
Android Gradle Plugin update 3.2.0-alpha16 instead of 3.1.2
Invalidate cache and restart/disabling configure on demand did not work for me. The only solution that helped me is to import the project from git again.
[UPD] Need to change "com.android.tools.build:gradle" from 3.1.2 to 3.1.1
All I needed to do in this case was to use "nuclear function" in Android Studio:
File -> Invalidate Caches / Restart....
Like in many other cases, this helped to make Gradle sync and project build working again. I'm using gradle-4.6-all and Gradle Plugin com.android.tools.build:gradle:3.1.3.
Go to File->Build,Excution,Deployment->Compiler and Uncheck Configure on Demand
gradle/wrapper/gradle-wrapper.properties
Update the gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
Build > Rebuild Project
Good Luck
Source

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

I am getting this kind of error, how to fix it.
Error:Unable to load class 'org.gradle.tooling.internal.protocol.test.InternalTestExecutionConnection'.
Possible causes for this unexpected error 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 updated my Android Studio to 2.3 and it asked me to update my gradle plugin to 3.3 that created issues with my running projects.
I've gone through all the Stack solutions and nothing worked for me except this workaround:
I changed my distribution url in gradle-wrapper.properties with this one.
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
(permanent link list here : https://services.gradle.org/distributions/)
My project is up and running.It just asked me to update to gradle build tools 25.0.0 which I did so. Everything is fine now :)
Go to the project section and select gradle scripts menu.
Under script, menu select gradle -wrapper.properties
Then replace the distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip with "distributionUrl=https://services.gradle.org/distributions/gradle-3.4.1-all.zip"
note: distributions gradle will change depended upon the version of the android studio.
Make sure you have Internet Connection then:
1.For Window Users Go to > C:\Users\username\.gradle\wrapper\dists
2.For Linux users
Go to $HOME/.gradle (~/.gradle) and/or (Under Specific project)
<PROJECT_DIR>/.gradle
3.Delete the gradle file(s) with the problem(i.e the zipped folders with
missing with no its extracted file )
4.Sync the project with gradle files.
Delete corrupt files
This error occurs when Gradle files are not completely downloaded or corrupted by some other reason, so we have to redownload the files.
The easy way is to delete the old files in
C:\Users\username.gradle\wrapper\dists
and rebuild the project, Android Studio will automatically download the new files.
Watch the Tutorial
https://www.youtube.com/watch?v=u92_73vfA8M
or
follow steps :
Go to any browser
type gradle and press enter
you can specify any version you want after the
gradle keyword
i am downloading gradle 3.3
https://services.gradle.org/distributions
click on this link which is in description directly if you want
click on gradle 3.3 all.zip
wait for the download to complete
once the download is complete
extract the file to the location
c://user/your pc name /.gradle/wrapper/dists
wait till extraction it takes 5 mins to complete
Now open your project in android studio
9.go to file > settings >bulid ,exec,deployment > gradle
now change use default gradle to
use local gradle distributn
select the location where you had extracted gradle 3.3.zip
C:\Users\your pc name.gradle\wrapper\dists\gradle-3.3
click on OK
Now build starts again and
you can see now the build is successful and error is resolved
If you manually setup gradle also make sure projects build.gradle verison is compatible with it. See following as an example.
Project's build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
Manual gradle setup
A lot of answer to this questions but a few were helping. I want to give accurate and updated answer.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
This error happens when you bad internet connection or you put your computer to sleep while Android Studio is downloading the required dependencies.
How to resolve this issue.
Find out the project's Gradle version. You will find that in gradle-wrapper.properties in distributionUrl my gradle distribution was https\://services.gradle.org/distributions/gradle-6.5-all.zip that means gradle-6.5-all.zip is required to download and right now it is corrupted because of connection timeout. Lets find out this folder and delete this.
Go to $HOME/.gradle folder then to wrapper then to dists then find a folder that matches the gradle version name that required to download. In my case it was gradle-6.5-all.zip select this folder and delete it.
Now sync the project and make sure you have good internet connection and setting that will prevent your system going to sleep while downloading something.
Kindly delele all folders under the in /.graddle/version/
This is how i solved mine. good luck
Maybe you can run ./gradlew build -s in the terminal, the stacktrace would show you where went wrong.
Try the next step to "Refresh" your IDE (android studio)
1. Let Gradle rebuild your auto-genrated files by click Build | Rebuild
2. Also try Choose File | Invalidate Caches/Restart.
I resolved this issue by downloading current version of graddle from link given
download latest version of graddle possibly graddle 3.3
Then in next step i accessed .graddle/wrapper/dists dirctory from home directory on my Mac after showing up hidden system files and deleted previuos version folder residing there.
Now i put that downloaded latest version folder after uncompressing there.
Now restarted Android studio and problem was resolved.
If you are seeing this error in Android Studio 4.1 with Gradle 6.5 then you should move back to
classpath 'com.android.tools.build:gradle:4.0.2'
For some reason
classpath 'com.android.tools.build:gradle:4.2.0'
does not work correctly.
You can try this
first Open your Android Studio > open any project you're doing
click on File > Settings > Build,Execution,Deployment > Gradle
At Project-Level settings , there are 2 option to sync the gradle either usin the default or local.
now change from default to a local gradle distribution > gradle Home
select the path on your computer.
C:\Program Files\Android\Android Studio\gradle\gradle-4.1
click on OK
Now build starts again it should be solved.
Go to "C:\Users\.gradle\caches\". Delete all the files in the folder. Then Sync Gradle and Rebuild the project.
i deleted the gradle folder and then i did rebuild, every thing working fine
If you using Ubuntu, So firstly you have unhide all files from your home directory or where located your android studio folder :
Go to your home directory and unhide all files by using ctrl+h
You found .gradle folder
Inside .gradle -> wrapper
You can found dists folder, So delete this dists folder
Create a New Project than your Gradle file re-downloaded
Congo you successfully build project
check out distributionUrl setting in gradle-wrapper.properties. I changed https to http, then my problem was solved.
In my case,just change http to https in the gradle-wrapper and Sync it.
Just reimport project. :)
I tried cleaning up the cache and refreshing dependencies doesn't work but failed.
Clear .gradle folder and rebuild
Open C:\Users\Username.gradle\wrapper\dists\
Open latest gradle folder, e.g. gradle-4.1-rc-1-all
You will find a random folder named 936kh1brdchce6fvd2c1o8t8x
Download zip file of similar name
eg: https://downloads.gradle.org/distributions/gradle-4.1-rc-1-all.zip
Save it in this folder
Restart Android studio
It will automatically extract the zip folder and Error will clear
Finally solved this problem.
If you just copy new version's files to old folder and override files,you may face the same question as me.
To solve it:
makesure you saved your all settings.
close AS,DELETE ALL files of your mixed version.
extract new version to your empty folder.
It works for me.
For me, i was cloning a project from github which used a version of gradle higher than that which i had installed. I had two choices:
Open gradle.wrapper-properties of a project you have that's building successfully, and copy the line that says distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip. Use this to replace the same value in the project that's failing. That should do the trick.
Your build might still fail if the gradle version used to build the project is higher than that which you just added. For this you should update the gradle version to the latest.
In my case I hade to change from:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
**apply plugin :'com.google.gms.google-services'**
}
to
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
}
search on google "download java 11"
click oracle website download your java to your platform and install it.
go to android studio click CTRL+SHIFT+ALT(Project Structure)
SDK Location Tab Show the path of JDK location which you installed
In your gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
This won't download and always gives 'gradle cache corrupt' error, but a small change makes it work fine
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Now sync the gradle again and it's done.
I will generalize the issue that you might face
Inside module's build.gradle :
Change:
plugins {
[...]
apply plugin:'whatever_you_have'
}
to
plugins {
[...]
id 'whatever_you_have'
}
In other words instead of apply plugin: use id
Unable to find method ''void
com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension,
com.android.build.api.extension.VariantSelector,
kotlin.jvm.functions.Function1, int, java.lang.Object)'' 'void
com.android.build.api.extension.AndroidComponentsExtension$DefaultImpls.androidTest$default(com.android.build.api.extension.AndroidComponentsExtension,
com.android.build.api.extension.VariantSelector,
kotlin.jvm.functions.Function1, int, java.lang.Object)'
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.
It happened to me after upgrading Android Studio to 4.2.0.
Updating the hilt classpath on build.gradle to 2.35 fixed these issues for me.
classpath "com.google.dagger:hilt-android-gradle-plugin:$2.35"
If you have updated your android studio, then go to FILE, Project Structure, Project, then check gradle version. Before that check your gradle version in C:\Program Files\Android\Android Studio\gradle and check the version if it matches then sync again else change the gradle version in android studio and sync again.
I had a similar problem after cloning AnySoftKeyboard and opening it in Android Studio. What worked for me was deleting the AynSoftKeyboard/gradle folder and then cleaning the project via menu item Build > Clean Project.
So try deleting YourProject/gradle folder and clean the project to trigger a Gradle sync.
Hope it works for your case.
download gradle from here for your OS and extract the file and paste the inner folder into installLocation/gradle
than in Android Studio Goto File > Settings > bulid ,exec,deployment > gradle and choose local gradle option and provide the file path of your new downloaded gradle and hit ok it works :)

Android Studio - Could not download artifact

I am new to Android Studio IDE. I have created a sample project using Android Studio and when I tried to build it, it comes with the following error.
Error:A problem occurred configuring root project 'SampleApp".
> Could not resolve all dependencies for configuration ':classpath'.
> Could not download artifact 'org.bouncycastle:bcprov-jdk15on:1.48:bcprov-jdk15on.jar': No
cached version available for offline mode
Can anyone please figure out what I did wrong.
It needs to download that library in order to do your build, but you've (perhaps inadvertantly) put Android Studio into offline mode. To fix it, go to Preferences > Gradle and ensure that the "Offline work" checkbox is not checked.
I think you should add following code at the top level of your build.gradle:
repositories {
mavenCentral()}
You might also need to try with --refresh-dependencies.
You can take more help from this here.

Categories

Resources