Gradle Sync Failure In Android Studio - android-studio

As soon as I open an Android Studio project, I get a warning saying "Gradle Sync Failed" and this error:
Gradle sync failed: Cause: ch.qos.logback.classic.LoggerContext cannot be cast to org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext
My build.gradle is:
// 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.2.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
}
I've tried the suggested fixes and a clean install several times to no avail. I have OSX 10.10 with JDK 8 installed. Thanks in advance.

Remove slf4j* jars files from /Library/Java/Extensions.
Use below command to see files in Extensions directory:
ls /Library/Java/Extensions/
See this question and it's answer here
I hope it's helps you.

Related

I can't sync my project to gradle, I have this error "Add google Maven repository and sync project"

I Tried adding these codes in my repositories:
google()
jcenter()
maven {
url 'https://maven.google.com'
}
but even now I can't sync gradle
I had this error when I opened an outdated learning project.
I took these steps to solve my problem:
1. Add google Maven repository and sync project.
2. Do refactor.
3. Update Gradle plugin and sync.
(Optional) 4. If you opened an older project as I did in my example then don't forget to set up compileSdkVersion, minSdkVersion and targetSdkVersion to your installed SDK version in build.gradle(Module:app) file.
In my example, this is my updated build.gradle(Project: "Project_name") file.
My mistake was I was thinking that
classpath 'com.android.tools.build:gradle:4.2.0-alpha13'
in build.gradle, is same as
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
in gradle-wrapper.properties
so please go to project tab in project structure and set android gradle plugin version and gradle version in listbox and sync it again
In the project's build.gradle, modify as follows:
buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} // <-- add
//jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
allprojects {
repositories {
google()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} // <-- add
//jcenter()
}
}
I hope this help

Gradle Builds with NanoHTTPD, but class cannot import

This is probably a really stupid question, but after messing with this for 2 hours, I cannot seem to resolve.
I am wanting to use nanohttpd in an android app as a lightweight local webserver. The gradle seems to find nanohttpd and builds just fine with the dependency; However, I cannot seem to include it in any of my java class files.
for example: I create a new class file and use:
import org.nanohttpd.protocols.http.response.Response;
I get the following error:
error: package org.nanohttpd.protocols.http.response does not exist
It also does not detect org.nanohttpd.* or even org.*
Below is my Gradle dependency line from the app level Gradle.build:
implementation group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'
This identifies current version and seems to work.
And here is the full Project level build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.10"
classpath "org.nanohttpd:nanohttpd:2.3.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Apparently you cannot import org.nanohttpd.
The correct syntax is:
import fi.iki.elonen.NanoHTTPD.*;
Not sure if this is different from the nanohttpd github project...

android build gradle error (android 3.1.3) ? Connection timed out: connect

my gradle build Could not GET
'https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'.166 INTERNAL CALLS
'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'
my 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.1.3'
// 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 propriety
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Do you have antvirus on you PC? Try to switch off it..
I had the same issue:
Could not get resource
https://jcenter.bintray.com/com/android/databinding/compiler/3.1.3/compiler-3.1.3.pom
I have Kasperskiy Internet Secirity on my PC. I was able to buld project just after disable it and go to File-> Invalidate cache and restart. Then project was builded successfully.
Then I enable KIS back and can build project without issues.

Android Studio: Unable to load class 'com.google.common.base.Preconditions', Gradle Sync Failed

When i try opening my projects on Android Studio 3.1.2, I get this Gradle Project Sync failed error with the message below
Unable to load class 'com.google.common.base.Preconditions'. 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. 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.
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.4-all.zip
build.gradle file
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'kotlin'
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
The problem has been solved.
I deleted the .gradle folder in my home user directory which made Android Studio re-download all the files for the current version of gradle. It took quite a while to download and sync the first time but it has solved the problem.
Thank you very much for your assistance #Luis Henriques
Clean and rebuild your project;
Check if you are working on offline mode:
File > Settings > Search for "offline" > uncheck "offline work"
After unchecking offline work, clean and rebuild again.
If it doesn't work, my guess is exactly what it says:
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.
Let me know if it worked.
UPDATE:
Why do you have:
repositories {
mavenCentral()
}
...
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
Instead of:
buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
...
Also use "implementation" instead of "compile". So:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
And why did you set these up in your project.gradle instead of in your app.gradle?
I think your gradle file is poorly structured. Hence the problem. Why don't you see how the default gradle files are set up and compare them with yours?
Hope this helps.
Your local gradle distribution my be corrupt. Delete it and redownload it.

how to fix Gradle project refresh failed

why i'm gonna get this error?, how to fix it, i've tried to follow any intro, but it couldn't get fixed.
Gradle project refresh failed
Error:Could not download artifact 'com.android.tools.build:builder:0.12.2:builder.jar': No cached version available for offline mode
my build.gradle
// 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:0.12.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
thanks for your solution/ideas.
Go to Settings->Build,Execution,Deployment->Gradle. And check Offline Work and try again.
Go to Settings->type gradle in search box and click on the result and uncheck the offline work

Resources