Android Studio - Gradle sync error on gradle-diagnostics-X.X.X.jar - android-studio

I've just updated Android Studio and I can't sync my project anymore.
The event log reports:
Gradle sync failed: /Applications/Android Studio.app/Contents/gradle/gradle-X.X.X/lib/plugins/gradle-diagnostics-X.X.X.jar (No such file or directory)

To solve the Gradle sync error, open gradle-wrapper.properties file and update the Gradle wrapper distribution version from:
distributionUrl=https\://services.gradle.org/distributions/gradle-X.X.X-all.zip
To:
Android Studio 3.4
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Android Studio 2.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
Android Studio 2.2 distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Android Studio 2.1 distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
Android Studio 2.0 distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Android Studio 1.5 distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Android Studio 1.3 distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
You can find the latest Gradle wrapper version visiting:
https://services.gradle.org/distributions/
EDIT:
As a side note, as #SeBsZ suggests,
the official repository of the Android Gradle plugin switched from MavenCentral to jCenter (see Bintray blog post).
Make sure your project build.gradle file contains the new repository and the new classpath:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is not strictly related to the question problem, but since we are already migrating to the new IDE preview it's better to make sure everything is in place.

If, like me, you are using an older project then you might still be using the maven repository. Make sure you change the repositories in your top-level build.gradle from maven() to jcenter(). Then make sure you are using the correct dependency as well: classpath 'com.android.tools.build:gradle:1.3.0-beta1' for the new 1.3 preview.

For me helped to set chmod on the .gradle directory to 777. After this whole Android studio started working correctly.

I got the same issue after updating android studio to 3.4
I resolve this updatig gradle-wrapper.properties
I had
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I leave
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and with this To solve the Gradle sync error.

This is the weirdest thing ever and I never expected it to work but this:
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
worked and got everything fixed (it was the '\' after https). It does make sense since that is an actual link to a file.

check your .bash_profile file and make sure your GRADLE_HOME points to a valid path, if things were working and you face this issue after android studio update, chances are your gradle got updated too.
Here is the example of my gradle home in .bash_profile:
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-2.14.1/bin

Had the same problem with a newly set up Android Studio 2.2.2, gradle wrapper 2.14.1. I loaded the project before i installed the needed android-23 library and installed java after Android Studio installation.
Error message in Android Studio 2.2.2:
Error:The specified Gradle distribution
'https://services.gradle.org/distributions/gradle-2.14.1-all.zip' does
not appear to contain a Gradle distribution.
Error message in cmd:
projectfolder> gradlew
Exception in thread "main" java.lang.NullPointerException
at org.gradle.wrapper.BootstrapMainStarter.findLauncherJar(BootstrapMainStarter.java:34)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:25)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
When i used gradle from cmd however it worked
projectfolder> set PATH=%PATH%;C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> set GRADLE_HOME=C:\AndroidStudio2.0\gradle\gradle-2.14.1\bin\
projectfolder> cd C:\projectfolder\
projectfolder> gradle
BUILD SUCCESSFUL
In cmd i see that the gradle versions and android sdk version were correct
C:\>set | find "JAVA_HOME"
JAVA_HOME=C:\Java\jdk1.8.0_111\
However in C:\Users\.AndroidStudio2.2\system\log\idea.log it said something else:
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
2016-11-29 16:04:10,597 [ 107684] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/AndroidStudio2.0/jre
After messing up Android Studio config files i ended up reinstalling everything in correct order (Java, Android Studio, Project) and it worked.

I got the same issue after updating my android studio to 1.5
Here is my error stack trace.
Error:A problem occurred configuring root project 'Kargo'.
java.io.FileNotFoundException: /home/adiyatmubarak/Documents/android-studio/gradle/gradle-2.4/lib/plugins/gradle-diagnostics-2.4.jar (No such file or directory)
After I checked to the android studio instalation directory within gradle, my gradle was gradle-2.8 I don't know how to setup my android studio path location, but for temporary fix I just rename it to gradle-2.4 and my problem solved.

Related

Sync failed and "Unable to find Gradle tasks to build" after upgrading from Android Studio 2021.3.1 to 2022.1.1

I found several SO posts describing similar issues, but they are outdated and none were found to be helpful in regard to my upgrade to the latest version of Android Studio.
After upgrading my Android Studio from version 2021.3.1 to version 2022.1.1, my attempt to File > Sync Project with Gradle Files results in Sync failed (within less than 200ms).
When I try to Build > Rebuild Project, I get the following error:
Unable to find Gradle tasks to build: [:].
Build mode: REBUILD.
Tests: None.
There is no :app in any of my settings.gradle files.
I did File > Invalidate Caches... (all of them) and restarted AS, but this didn't help.
I also deleted all build folders, but this didn't help.
Any idea how to solve this?
Right-clicking the Sync failed to Reload Gradle Project results in the same failure but it opens now a bar on top of the editor window with the Show Log in Explorer link. When I click it, I indeed find idea.log in C:\Users\WebViewer\AppData\Local\Google\AndroidStudio2022.1\log. I am inspecting it now...
Update:
The first thing I noticed in idea.log is the following exception:
org.gradle.tooling.GradleConnectionException: Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-bin.zip'.
...
Caused by: org.gradle.internal.jvm.JavaHomeException: The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe
Thanks to this SO tip, I did mklink /D "jre" "jbr" which all of a sudden revived Android Studio and started to download lots of Gradle related packages.
I still have "Gradle Sync issues" but at least Android Studio prompts me now how to solve them:
but... according to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, why is Android Studio asking for a minimum of 7.5?
Problem solved.
For the benefit of all, I am posting here a summary of what I did to solve it:
When a laconic "Sync failed" is all Android Studio provides, C:\Users\<yourname>\AppData\Local\Google\AndroidStudio2022.1\log\idea.log is key to finding clues to the mystery.
In my case, it was failure to find and run the embedded Java version. So, I did mklink /D "jre" "jbr" which miraculously revived the build process (see https://github.com/flutter/flutter/issues/106674#issuecomment-1381685888).
Under File > Settings > Build Tools > Gradle, this is the Java version that works for me:
I then tried to follow Sync's output to use Gradle 7.5.0. It could not be found on any of the repositories in my top level build.gradle and resulted in chasing my tail... According to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, so I reverted to using it (why didn't it work the first time, I don't know) and here is my working top level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1")
classpath("org.mockito:mockito-inline:4.11.0")
}
}
allprojects {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

How i can build old Android project in Android Studio

i have to build this project but getting error because it is so old.
here is the project git hub link
i am using latest android studio version
Try the following:
Change gradle version in build.gradle , change the version in the following line in the file: classpath 'com.android.tools.build:gradle:2.2.3'.
In the file gradle/wrapper/gradle-wrapper.properties, update the gradle version in this line: distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip . Sync the project again, it should work. If it doesn't restart android studio again. It should build successfully afterward.
PS: See what gradle version you use according to your android studio version.

I need to solve this problem about android studio

As you can see here is my problem with android studio I have been looking for solutions 3 days now but I didn't find any
Minimum supported Gradle version is 6.1.1 current version is 5.2.1
Please fix the project's gradle settings.
Fix gradle wrapper and re-import project
Open gradle wrapper properties
Gradle settings
Go to File > Project Structure > Project and change your Gradle Version there.

Android Studio can't open project

I've recently get update notification of android studio 2.3, after the update it's not opening any project and throwing error:
[plugin: com.darkklord.gradle.metric.core]
after downgrading and reinstalling i still have this issue, can anyone please help me on this topic ?
Download latest plugin from here: https://plugins.jetbrains.com/plugin/9197-android-gradle-metrics--checkstyle
Install Plugin manually from disk.
Restart Android Studio (The error will still occur)
Remove plugin in IDE.
Restart
You might also uninstall the refrenzed plugins Checkstyle and PMD
You need to change your dependency
classpath 'com.android.tools.build:gradle:3.1.0'
Sometimes you need to change name of project manually(look at AndroidStudioProjects folder) that you opened lastly.
After changing name, android studio will show all projects,
open one of them,
in file menu,
click open button,
then open your desire project (or change its name to its previous name)
change build:gradle plugin to:
classpath 'com.android.tools.build:gradle:3.3.2'
(in app gradle file)
I made sure that my Gradle version was compatible with my android gradle plug in. In my case I was using Gradle 6.0.1 and when I changed my android gradle plug in to version 3.5.3 the problem went away.
Project Structure----->> Project ------>> Android Gradle plug in version 3.5.3.
[https://docs.gradle.org/6.0.1/release-notes.html
[Java 14 and later versions are not yet supported.
Compatibility Notes
A Java version between 8 and 13 is required to execute Gradle.
Java 6 and 7 can still be used for compilation and forked test execution. Just like Gradle 5.x, any supported version of Java can be used for compile or test.
This version of Gradle is tested with
-------->>>>>>>>Android Gradle Plugin 3.4, 3.5 and 3.6
Kotlin 1.3.21 through 1.3.50
Other versions may or may not work.]]]]
I hope this helps

Cloning a project in Android Studio causes gradle exception

I have ligdx/robovm/gradle/android studio project with core, ios, android and desktop subprojects. I wanted to clone android subproject and create very similar one (I named it android-full). I've copy-pasted android directory and renamed it as well as stuff inside it's (build.gradle, AndroidManifest.xml). In settings.gradle I've added 'android-full' to the list. In build.gradle (root directory) I've copy-pasted project(":android") to project(":android-full"). When I'm trying to sync gradle I'm getting an exception:
Error:exception during working with external system:
Full stacktrace from logs here:
http://pastebin.com/T2XUWtYN
A guy from libgdx forums even created github repo with demo project for me (with 2 android subprojects ofc). Gradle works on it without any problem. Here it is: https://github.com/piotr-j/doubledroid
But when I've copy-pasted source code from core/src and android/android-full (without build.gradle) I've immediately got the same exception. I also compared all gradle files with diff checker and they're almost the same (structure is the same as well as version of gradle, I only have more libs).
I use latest android studio (1.4) and gradle 2.4.
I've tried restarting android studio, doing everything again from scratch, deleting .gradle directory, messing in .idea configs and still the same exception, which isn't very informative.
I don't understand how, but I fixed the problem. I just imported it in Eclipse (with gradle plugin). Project appeared without any problem. Then I realized there were fix small bugs in code, cleaned & builded everything again. Then project worked, I closed it and opened Android Studio again. Then it just worked! Some gradle vs android studio bug I guess.

Resources