Gradle - Could not create an instance of Tooling API implementation - android

I'm trying to import a project from GitHub and build/run it on Android Studio. I am getting the following error:
"Error:Could not create an instance of Tooling API implementation
using the specified Gradle distribution
'https://services.gradle.org/distributions/gradle-2.4-all.zip'."
I have tried the following:
Invalidate Cache and Restart
Changing the distributionURL in gradle-wrapper/properties to 2.5 etc.
Deleting build.gradle and restarting
These are ideas I got from several other posts on stackoverflow so I cannot explain why I tried these. (I'm very fairly new to Android Studio).
My build.gradle file looks like this:
// 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:1.5.1'
// 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 was facing a similar issue, updating the Gradle version in distributionUrl solved it.
distributionUrl field is present under this directory:
project-root-directory/gradle/wrapper/gradle-wrapper.properties

Please, change
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Then change
classpath 'com.android.tools.build:gradle:1.5.1'
with
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
It should work.

For me I think it is permission issue. From Eclipse I have also faced the same issue. On my gradle installation path (i.e. /opt/gradle) I have make it chmod as 777. So that other tool can access the same. Run the following 2 commands -
cd /opt
sudo chmod 777 -R gradle

Java versions > 9 and Gradle versions >= 5.0.0 has some code breaking changes. Here is to go around them using Eclipse. It should be similar in AndroidStudio.
Install the latest version of gradle from its distribution site
("https://services.gradle.org/distributions/") and
unzip the it on your PC.
When importing the gradle project in eclipse select the option "local installation
directory" and point to the folder where you unzip gradle.
(Bonus) if it is a LibGDX project, you need to also change the following in the Desktop
build file due to code breaking changes between gradle versions <5.0.0 and >=5.0.0.
Change "sourceSets.main.output.classesDir" to "sourceSets.main.output.classesDirs".
This is working for me and I am using LibGDX with Java 11 and Gradle 5.2.1 on Windows 10 while running Eclipse 2018-12.

Try deleting the folder gradle-2.4-all in ~/.gradle/wrapper/dists

Related

Gradle Build Failed - Gradle version 1.10 is required. Current version is 2.8

[![enter image description here][1]][1]
I have modified the file .but still not working. Can you please tell exactly where I am going wrong. previously,It was showing error-
Required gradle 1.10 , but currently using 2.8
Follow these steps:
Go to Settings > Builds ,Execution , Deployment -> Build Tools -> Gradle and set Use default gradle wrapper
Edit the Project\gradle\wrapper\gradle-wrapper.properties file and set the field distributionUrl with:
distributionUrl=https://services.gradle.org/distributions/gradle-2.10-all.zip
Move the gradle plugin outside the dependecies block and inside the buildscript block:
Somenthing like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
It might help people like me-
I was adding dependencies in the wrong gradle.build file.
Later I placed .jar files in /lib folder and connected that to gradle.build
I updated my Sdk as well.

Gradle version 2.2 is required. Current version is 2.10

I am trying to use gradle build. It gives me error saying that
Failed to apply plugin [id 'com.android.library']
Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /home/sanjeewa/workspace/Android/UVCCamera/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip
But my gradle-wrapper.properties includes gradle-2.4-all.zip. I have changed it to gradle-2.2-all.zip
Still same problem.
When I run gradle -version in terminal Gradle 2.10 shows as version.
How to solve that error??
my build gradle file is
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Open gradle-wrapper.properties
Change this line:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
with
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Go to build.gradle (Project: your_app_name)
Change this line
classpath 'com.android.tools.build:gradle:XXX'
to this
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
or
classpath 'com.android.tools.build:gradle:1.5.0'
Don't click Sync Now
From menu choose File -> Invalidate Caches/Restart...
Choose first option: Invalidate and Restart
Android Studio would restart. After this, it should work normally
Hope it help
Current work around is to overrideVersionCheck: In your build.gradle
buildscript {
System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true'
...
}
Check this link for more Details
Just Change in build.gradle file
classpath 'com.android.tools.build:gradle:1.3.0'
To
classpath 'com.android.tools.build:gradle:2.0.0'
Now GoTo -> menu choose File -> Invalidate Caches/Restart...
Choose first option: Invalidate and Restart
Android Studio would restart.
After this, it should work normally.
Based on
https://developer.android.com/studio/releases/gradle-plugin.html ...
The following table lists which version of Gradle is required for each version of the Android plugin for Gradle.
For the best performance, you should use the latest possible version of both Gradle and the Android plugin.
So, the Plugin version with Required Gradle version should be match.
Here's what I did to fix this:
1) Create a new project
2) open the gradle-wrapper.properties file and copy the distributionUrl to your project e.g.:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
3) open the build.gradle (Project) and copy the gradle dependency to your project e.g.:
classpath 'com.android.tools.build:gradle:2.3.0-beta1'
4) File --> Invalidate Caches / Restart (I think a re-sync may have sufficed, but didn't try it)
5) Delete that project you made (optional)
Look, this is a silly way to do things, but Android Studio is free so who am I to complain...
Use ./gradlew instead of gradle to resolve this issue.
The android studio and Gradle version looks like very bad managed. And there's tons of version in-capability issues. And the error message is mostly clueless. For this particular issue. The closest answer is from "Jitendra Singh". Change the version to:
classpath 'com.android.tools.build:gradle:2.0.0'
But in my case: Android studio 2.2 RC, I still get another error:
Could not find matching constructor for: com.android.build.gradle.internal.LibraryTaskManager(org.gradle.api.internal.project.DefaultProject_Decorated, com.android.builder.core.AndroidBuilder, android.databinding.tool.DataBindingBuilder, com.android.build.gradle.LibraryExtension_Decorated, com.android.build.gradle.internal.SdkHandler, com.android.build.gradle.internal.DependencyManager, org.gradle.tooling.provider.model.internal.DefaultToolingModelBuilderRegistry)
So I went to the maven central to find the latest com.android.tools.build:gradle version which is 2.1.3 for now. So after change to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}
Solved my problem eventually.
I Had similar issue. Every project has his own gradle folder, check if in your project root there's another gradle folder:
/my_projects_root_folder/project/gradle
/my_projects_root_folder/gradle
If so, in every folder you'll find /gradle/wrapper/gradle-wrapper.properties.
Check if in /my_projects_root_folder/gradle/gradle-wrapper.properties gradle version at least match /my_projects_root_folder/ project/ gradle/ gradle-wrapper.properties gradle version
Or just delete/rename your /my_projects_root_folder/gradle and restart android studio and let Gradle sync work and download required gradle.

Android 1.5 Gradle Sync never completes

I recently upgraded to Android Studio 1.5. However, after update, Gradle gets stuck at "Refreshing [project] Gradle Project" and never stops.
Previous version of Android Studio worked just fine.
How do I solve this?
I am on an Ubuntu 15.10 64bit machine.
Edit:
So far, I have tried deleting Android Studio from /opt and downloading the latest version. Didnt help.
I also tried removing the ~/.AndroidStudio1.5 directory. To no avail.
This is in my "Event Log"
Gradle sync started
NullPointerException: null
In your Android Project change gradle-wrapper.properties file, which is in *project/gradle/wrapper:
From:
distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip
To:
distributionUrl=https://services.gradle.org/distributions/gradle-2.8-all.zip
And also change the project build.gradle like below:
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
In your build.gradle for the project, update your classpath to gradle 1.5.0
Example:
// 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:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
go to Preferences > Build, Execution > Build Tools > Gradle and change the Gradle Home path. I had to change mine because it had the wrong value, it was /Applications/Android Studio.app/Contents/gradle/gradle-2.4 and I changed it to /Applications/Android Studio.app/Contents/gradle/gradle-2.8
I had the same problem. My JAVA_HOME wasn't set to the right directory. Ehsun Mehranvaris answer is more like a hack, than a solution. I tried to built the android project per terminal with ./gradlew and it told me JAVA_HOME wasn't set correctly.
To get the path of your java enter in terminal:
readlink -f $(which java)
Set your JAVA_HOME like this in terminal:
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre
After that, I switched to the android project directory in the terminal and did run this command:
./gradlew
This will build your project and in my case it downloaded the latest gradle 2.8 package. Android Studio might download the package itself, if you set the JAVA_HOME correctly. Didn't try that.
Now you can use the default gradle wrapper from Android Studio and don't need to edit any property file manually. You find that at Preferences > Build, Execution > Build Tools > Gradle

Android Studio Gradle Error at Compile Time

I have an Android App in Android Studio. When I build project with Gradle File,it gives me one error at compile time.
Error Report:
Error:org.gradle.api.internal.changedetection.state.DefaultFileCollectionSnapshotter$FileCollectionSnapshotImpl cannot be cast to
org.gradle.api.internal.changedetection.state.OutputFilesCollectionSnapshotter$OutputFilesSnapshot
Please Give me solution about this error.
1.delete {project dir}/.gradle/{gradle distribution version dir}
{gradle distribution version dir} is whatever the gradle distribution version you use (ref: https://developer.android.com/studio/releases/gradle-plugin.html#revisions). For example, it can be "1.9" or "2.10" or some other version number.
2.Sync Project with Gradle File
This is what worked for me:
Android Studio -> File -> Invalidate Caches and Restart
Stoping the gradle daemon worked for me.
go to terminal and run ./gradlew --stop
Rebuild the project.
For me, I have tried to:
(Doesn't Work):
invalidate caches.
stop third-party plugins.
remove gradle repository.
remove {project dir}/.gradle/2.*(which are not current gradle version)
(Work):
Finally, the answer is like #MAC113's,
delete {project dir}/.gradle/2.10 (2.10 is my current gradle version)
None of those solutions working for me. I ended up by:
Clone my project to a new folder
Remove .gradle, .idea folders
Add as a new project (File > Open > [new folder])
It works! It's a weird issue that I've ever met.
Easy solution! Just fixed on my side. It was a project exported from Unity Studio.
After exporting from Unity, the gradle was like com.android.tools.build:gradle:2.1.0
I then changed it to com.android.tools.build:gradle:2.2.0 and it worked.
Also never forget to change the repositories from mavencenteral to jcenter().
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
If you using GreenDao You should update it to the lastest version
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0' // add plugin
implementation 'org.greenrobot:greendao:3.3.0'
Deleting .gradle folder works for me

Could not resolve all dependencies for configuration ':classpath'

I cant seem to get build tools for the latest gradle at all. I suspect its something to do with proxy setting for gradle. I have had a good look online but still cant seem to find a solution. I use gradle 2.1.
I created gradle.properties file in my /home/user/.gradle folder with these setting.
systemProp.http.proxyHost=proxy
systemProp.http.proxyPort=80
systemProp.http.proxyUser=myusername
systemProp.http.proxyPassword=password
systemProp.https.proxyHost=proxy
systemProp.https.proxyPort=80
systemProp.https.proxyUser=myusername
systemProp.https.proxyPassword=password
Here is my global build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.0'
classpath fileTree(dir: 'build-libs', include: '*.jar')
}
}
allprojects {
repositories {
mavenCentral()
}
}
And here is the error i get when running gradlew
Could not HEAD 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/0.13.0/gradle-0.13.0.pom'.
peer not authenticated
What am I missing? that maven link opens fine in a browser.
Right, I'm not sure if it will work for others but worked for me.
I changed proxyPort to 8080 and used jcenter instead of Maven. But I had to apply expeption to use HTTP instead of HTTPS. This is what I have in my build.gradle for build script and allprojects
buildscript {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
allprojects {
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
}
UPDATE: 06/08
I have recently updated Gradle and plugin version and had some problems. It was complaining about plugin com.android.application
I did some digging around and changed
jcenter {
url "http://jcenter.bintray.com/"
}
to
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
Find and Replace:
jcenter()
maven {
url "https://maven.google.com"
}
to:
maven {
url "https://maven.google.com"
}
jcenter()
For newer android studio 3.0.0 and gradle update, this needed to be included in project level build.gradle file for android Gradle build tools and related dependencies since Google moved to its own maven repository.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I'm using Gradle plugin 3.0.1 and saw this error. Not sure what caused this but the solution that works for me is to stop the running Gradle daemon by ./gradlew --stop.
The solution is in your build.gradle change this block:
allprojects {
repositories {
jcenter()
google()
}
}
to google in first position :
allprojects {
repositories {
google()
jcenter()
}
}
late but it worked for me:
change your dns setting by going Network and sharing center.
In left pane choose change adapter setting
-right click on your network connection
-properties
-select ipv4
-properties
- now in dns server setting:-
-choose the option use the following dns server addresses
and use google dns server 8.8.8.8 as preferred dns server and
8.8.4.4 as alternate dns server.
it will solve your problem.
In the Android Studio v4.0, you should be off the Gradle offline-mode and retry to sync Gradle.
I try to modify the repositories and import the cer to java, but both failed, then I upgrade my jdk version from 1.8.0_66 to 1.8.0_74, gradle build success.
I got the same problem. Just use File->INVALIDATE CACHES AND RESTART
6 years later here, but for them who are stil facing this issue, I solved it as following.
It happened when my module had a different gradle version than the main project. I had gradle version 3.5.3 in project and an older version in module. So, I Just updated that version. The file is here:
./node-modules/[module-name]/android/build.gradle
In my case deleting the .gradle folder worked for me.
In my case, my Android Studio version was 3.6.1 and i have modified the classpath like below;
classpath 'com.android.tools.build:gradle:3.6.1'
and that error was gone.
Go to
File --> Invalidate Caches / Restart.
It worked for me.
Android Studio > view > tool Windows > Gradle > click toggle offline mode (besides gradle settings icon)
this work for me :)
I had a same problem and I fix it with the following steps:
check the event log and if you see the errors like "cash version
is not available for the offline mode" follow the steps.
click on View => Gradle then new window will open.
click on the WIFI icon and then sync the Gradle.
"if you see different errors from what I mentioned in number one,
please go to the file -> project structure -> and there is suggestion"
Tools > SDK Manager > SDK Tools > Show Package Details
and remove all the old versions
I installed new Android Studio and faced with this problem. Nothing is helped me except of downloading a few more Android SDK versions:
Added Android Q and Android Pie to downloaded and installed SDK
Well if anyone facing with this problem after updating android studio to 4.2, the problem is about kotlin version. changing cotlin version line from "ext.kotlin_version = "1.5.0-release-764" to "ext.kotlin_version = "1.5.0" may solve your issue. Here is the link which has more information about it:
https://exerror.com/cant-create-new-kotlin-project-after-updating-to-android-studio-4-2/
You should have gradle-wrapper.properties inside gradle/wrapper folder.
Make sure you are using the right distributionURL, and the latest one. It should look something like this :
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
I Updated my android studio to latest version: Android Studio - Arctic Fox | 2020.3.1
Then it was showing this error. To solve this error, you have to follow these steps:
File>project Structure>project
Change Android Gradle Plugin version: 7.0.0 and Gradle Version: 7.0.2
then Go to file>setting>Build, Execution, Deployment>Build Tools>Gradle
change Gradle JDK to 11 version if it is 1.8 version.
if notification popup for Gradle upgraded then tap on it and click on run selected steps.
sync project and rebuild your project if necessary.
I hope it will work for you, Thanks me later.
I encountered a similar issue while building a Java project on Jenkins using Gradle.
When I run the build on Jenkins, at some point it throws the error below:
22:37:05 + GRADLE_OPTS='-Xms8192M -Xmx8192M'
22:37:05 + gradle clean build '-Dorg.gradle.jvmargs=-XX:MaxPermSize=4096M -Xms4096M -Xmx8192M' --full-stacktrace
22:37:05
22:37:05 Welcome to Gradle 5.6.4!
22:37:05
22:37:05 Here are the highlights of this release:
22:37:05 - Incremental Groovy compilation
22:37:05 - Groovy compile avoidance
22:37:05 - Test fixtures for Java projects
22:37:05 - Manage plugin versions via settings script
22:37:05
22:37:05 For more details see https://docs.gradle.org/5.6.4/release-notes.html
22:37:05
22:37:05 Starting a Gradle Daemon (subsequent builds will be faster)
22:37:14 > Task :my-service:clean UP-TO-DATE
22:37:18 > Task :my-service:compileJava FAILED
22:37:18
22:37:18 FAILURE: Build failed with an exception.
22:37:18
22:37:18 * What went wrong:
22:37:18 Execution failed for task ':my-service:compileJava'.
22:37:18 > Could not resolve all files for configuration ':my:compileClasspath'.
22:37:18 > Could not download spring-boot-autoconfigure.jar (org.springframework.boot:spring-boot-autoconfigure:2.1.14.RELEASE)
22:37:18 > Could not get resource 'https://nexus.my-test.network/repository/maven-public/org/springframework/boot/spring-boot-autoconfigure/2.1.14.RELEASE/spring-boot-autoconfigure-2.1.14.RELEASE.jar'.
22:37:18 > Premature end of Content-Length delimited message body (expected: 1276879; received: 496657
22:37:18
22:37:18 * Try:
22:37:18 Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Here's how I fixed it:
So first I looked the previous builds and they were building fine except this last one, also we had not changed anything in the build process.
The issue was with our Nexus artifactory server that has not been running fine. The server stops responding sometimes.
I just restarted the server and re-tried the build and it worked fine.
That's all
**A problem occurred evaluating project ':app'.
Could not resolve all files for configuration 'classpath'.**
Solution:
Platform->cordova-support-google-services
In this file
Replace
classpath 'com.android.tools.build:gradle:+' to this
classpath 'com.android.tools.build:gradle:3.+'
There seems to be many different causes to this problem. My cause is different from other posted answers, so I'll go ahead and explain what my problem was just in case it's useful.
I have a set of custom gradle plugins that for all practical purposes can be thought of as a wrapper around four familiar plugins: "com.android.application", "com.application.library", "java" and "java-library". These wrapper plugin are responsible for actually applying those familiar plugins, along with supplying configuration data. The result is that it simplifies the "build.gradle.kts" scripts for modules in my various projects.
My wrapper plugin for the "java-library". Is pretty straight forward. It applies the "java-library" plugin and adds the "sourceCompatibility" and "targetCompatibility" values. I followed the pattern that others have suggested on how to set those values. Essentially doing something like: "project.tasks.withType<JavaCompile> { sourceCompatibility = ... }" That's what caused my problem. I changed the above to:
val javaExt:JavaPluginExtension = project.extensions.get("java") as JavaPluginExtension
javaExt.sourceCompatibility = JavaVersion.toVersion( versions.getProperty("java-source-compatibility"))
javaExt.targetCompatibility = JavaVersion.toVersion( versions.getProperty("java-target-compatibility"))
And that solved the issue for me! The only useful information I got from gradle on resolving the problem is that it let me know the offending module, which was a module that didn't need any dependencies. In order to track down what was going on, I put the offending module into a separate project. That's where I discovered that the problem was definitely related to my custom "java-library" wrapper plugin.
I basically just removed jcenter() from my repositories of project gradle in buildscript block, since i declared it in my app gradle.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
mavenLocal()
mavenCentral()
jcenter() //remove this line
}
you should have gradle.properties file defined for the build with proxy settings so that gradle knows how to use http connection
# This file contains the basics for Maven Version control and will be used by the Artifactory Release management
# These settings are for the root project and all sub-projects in this application
releaseVersion=1.0.0-SNAPSHOT
releaseGroup=com.xx.xx.xx
artifactory_user=
artifactory_password=
artifactory_contextUrl=https://artifactory.xxxx.com/artifactory/
systemProp.http.proxyHost=proxy.xxx.com
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.xxx.com
systemProp.https.proxyPort=8080
systemProp.http.nonProxyHosts=*.xxx.com|localhost|*.int.targoe.com
org.gradle.java.home=C:\\Program Files (x86)\\Java\\jdk1.8.0_121
I had this issue and it was because I hadn't added an exception for gradle in my firewall (TinyWall).
I got this issue solved by switching internet from Wifi to mobile hot-spot. It means this issue occurs due to network issue. I could also see below logs which confirms my understanding,
Connect to jcenter.bintray.com:443
[jcenter.bintray.com/75.126.118.188] failed: Connection timed out:
connect
and
Connect to repo1.maven.org:443 [repo1.maven.org/151.101.36.209]
failed: Connection timed out: connect
Hope it helps.
If adding google() into your build.gradle doesn't work try adding it at first place in your repositories section of node_modules/YOUR_PACKAGE/android/build.gradle file.
I am working with flutter in the VS Code.
In my case, I solved it by
stopping gradlew process in VS code using the below command
android/gradlew --stop
I changed the ext.kotlin_version in "build.gradle" to the previous one (from 1.5.0 back to 1.4.32) and that worked for me. Maybe the current Gradle version wasn't compatible with it.

Categories

Resources