grade sync failed when i want to import a project - android

i want to import a project in to android studio but i have an error gradle sync failed .
this is my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle sync failed: Cause: com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
Consult IDE log for more details (Help | Show Log)
i changed the distributionUrl but doesn't solve the problem .
my gradle-wrapper propertice:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
i searched the net for 3-4 hours but there was no solution for my problem that can solve my problem .

Hope it works
File → Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.

Related

My gradle build failed after I imported volley library

I have implemented phone number detection and SMS verification functionality into my project by referring to this project
https://www.programcreek.com/java-api-examples/?code=android%2Fidentity-samples%2Fidentity-samples-master%2FSmsVerification%2Fapp%2Fsrc%2Fmain%2Fjava%2Fcom%2Fgoogle%2Fsamples%2Fsmartlock%2Fsms_verify%2Fui%2FPhoneNumberActivity.java#
I downloaded and imported volley from the link below
https://github.com/google/volley
I am getting an error while building my project, please guide me I am new to android studio...
Error
Unable to find method 'org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal.getPublishableFiles()Lorg/gradle/api/file/FileCollection;'.
Possible causes for this unexpected error include:
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
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Update:
I deleted gradle file from C:\Users\MY PC.gradle\wrapper\dists and rebuilt the project and now I am getting this error
Error Unknown host 'services.gradle.org'. You may need to adjust the
proxy settings in Gradle. Enable Gradle 'offline mode' and sync
project Learn about configuring HTTP proxies in Gradle
change the distributionUrl in the gradle-wrapper.properties to distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip to get the build running again. This seems to be a similar problem Gradle sync failed: Unable to find method.

Not able to sync project with Gradle files (Re-download dependencies and sync project Gradle Problem)

After Android Studio Upgrade it shows following error when sync project with gradle files:
ERROR: Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Project Build Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle-wrapper properties
#Fri Apr 17 20:10:05 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
----Use graddle from is set to gradle-wrapper-properties file
----Android Gradle Plug in version is 3.6.2
Gradle version is 5.6.4
Changed gradle version also still showing error
Event log
9:03 PM Gradle sync failed: Cause: error in opening zip file
Consult IDE log for more details (Help | Show Log) (16 m 50 s 157 ms)
9:03 PM Android Studio is using the following JDK location when running Gradle:
I:\Android\android-studio-ide-192.6308749-windows32_17-4-2020\android-studio\jre
Using different JDK locations on different processes might cause Gradle to
spawn multiple daemons, for example, by executing Gradle tasks from a terminal
while using Android Studio.
More info...
Select a JDK from the File System
Do not show this warning again

Gradle project sync failed in android studio 3.1

my gradle.build contains
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and upon syncing project with gradle files is showing error as connection refused:connect .
There is a problem with Apply script build.gradle
Not able to resolve dependencies of classpath
Log file showing the below error
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom'.
at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:96)
Try using invalidate caches and restart in File Menu. Most of the time it works when studio have a new update.
Goto "File > Project Structure > SDK Location" menu and
Check "Use embedded JDK(recommended)".
It may be your JDK version problem.

Could not find com.android.tools.build:gradle:3.0.1

When I try to build my project with gradle wrapper I get this error:
./gradlew
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all files for configuration ':app:classpath'.
> Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://maven.fabric.io/public/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
Required by:
project :app
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
The same project builds OK in Android Studio.
I've already checked this and this but I'm using gradle wrapper version 4.1, have added google() repository and even tried setting android.enableAapt2=false. Any other tips? Thanks.
My root build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My gradle-wrapper.properties file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
UPDATE: Gabriele was right. I'd to add the repository also in the app/build.gradle file:
...
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
...
I guess that I was confused with this stament "To add one of these libraries to your build, include Google's Maven repository in your top-level build.gradle file" in here.
just wanted to leave an extra tip. When I installed Android Studio, I read somewhere that it was recommended to leave this configuration (with the '+' symbol)
build.gradle (project)
dependencies {
classpath 'com.android.tools.build:gradle:+'
.....
#more lines here
}
However, the project I am using uses an old version of gradle, and this line always requested the latest version. Took me a while to figure it out.
Check your proxy setting on Android Studio
File > Settings > Appearance
&
Behavior > System Settings > HTTP Proxy
Here was how I resolved the issue.
Change the root build.gradle file:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
.....
//other codes here
}

Android studio 2.3 refreshing continuously

I've recently updated android studio to 2.3...After update it is continuously refreshing the project.So I clicked on invalidate cache and restart..After that it is showing this error
This is the error image
This is my build.gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my gradle-wrapper.properties file
#Mon Mar 13 16:42:48 IST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
This is my gradle location
C:/Program Files/Android/Android Studio/gradle/gradle-3.2
Everything seems to be good to me.I dont know what should I change...Please help me
Click on the blue link - Upgrade Gradle Wrapper - that should fix it
For those who face similar problem here is the solution.Download gradle files manually from internet which is of around 80 mb and replace these new files with those of old ones in android stuido.

Categories

Resources