4

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'.

Tried everything, Android Studio still does not works. Re-installed 10 times, cleaned all .gradle .android folder. Created example project from scratch. Tried changing the gradle version. Nothing almost nothing works.

There is no system gradle, my Java version is javac 1.8.0_40

Contents of gradle config

// 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.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
}

Here are the contents of idea.log

2015-11-08 22:40:39,654 [ 471024]   WARN - nal.AbstractExternalSystemTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'. 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
    at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:158)
    at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.getUserFriendlyError(BaseGradleProjectResolverExtension.java:438)
    at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver.getUserFriendlyError(AndroidGradleProjectResolver.java:348)
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.getUserFriendlyError(AbstractProjectResolverExtension.java:164)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:366)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:332)
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:225)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:97)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:65)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
    at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
    at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
    at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4.execute(ExternalSystemUtil.java:540)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5$2.run(ExternalSystemUtil.java:621)
    at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
    at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)

2015-11-08 22:40:39,655 [ 471025]   WARN - radle.project.ProjectSetUpTask -  
2015-11-08 22:40:39,655 [ 471025]   INFO - radle.project.ProjectSetUpTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.

Consult IDE log for more details (Help | Show Log) 
2015-11-08 22:40:39,655 [ 471025]   INFO - ls.idea.gradle.GradleSyncState - Sync with Gradle for project 'My Application' failed: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.

Based on suggestions I installed gradle seperately, I had to fix this error https://issues.gradle.org/browse/GRADLE-1451 but I now have ANDROID_HOME, gradle defined and gradle --version works.

------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------

Build time:   2015-09-14 07:26:16 UTC
Build number: none
Revision:     c41505168da69fb0650f4e31c9e01b50ffc97893

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_40 (Oracle Corporation 25.40-b25)
OS:           Mac OS X 10.9.5 x86_64

**Yet I am still getting the same error from Android Studio. Also in a bizarre manner it simply refuses to accept the gradle home folder, always showing error that Gradle home folder is incorrect, even when I used lib or bin sub directory the error still remains. And it automatically switches back to the wrapper. **

Error:Could not create an instance of Tooling API implementation using the specified Gradle installation '/Users/aub3/gradle'.

When built from command like using 'gradle build' I get following error

:app:compileReleaseSources
:app:preDexRelease
:app:dexRelease
:app:packageRelease
:app:assembleRelease
:app:assemble
:app:compileLint
:app:lint
Ran lint on variant debug: 4 issues found
Ran lint on variant release: 4 issues found
Wrote HTML report to file:/Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.html
Wrote XML report to /Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.xml
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:compileDebugUnitTestJavaWithJavac
:app:compileDebugUnitTestSources
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebugUnitTest
java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to org.gradle.logging.internal.slf4j.OutputEventListenerBackedLoggerContext
    at org.gradle.logging.internal.slf4j.Slf4jLoggingConfigurer.configure(Slf4jLoggingConfigurer.java:42)
    at org.gradle.logging.internal.DefaultLoggingConfigurer.configure(DefaultLoggingConfigurer.java:34)
    at org.gradle.logging.internal.LoggingSystemAdapter.setLevel(LoggingSystemAdapter.java:55)
    at org.gradle.logging.internal.LoggingSystemAdapter.on(LoggingSystemAdapter.java:42)
    at org.gradle.logging.internal.DefaultLoggingManager$StartableLoggingSystem.start(DefaultLoggingManager.java:191)
    at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:60)
    at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:31)
    at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:58)
    at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:41)
    at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:49)
    at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:33)
    at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.main(GradleWorkerMain.java:74)
:app:testDebugUnitTest FAILED

FAILURE: Build failed with an exception.

I finally got gradle to assemble android project and install on a devide via gradle installDebug task using command line. Android Studio however still does NOT works.

Error:Could not create an instance of Tooling API implementation using the specified Gradle installation '/Users/aub3/gradle'.


Solved

I could get gradle wrapper to work with following

DEFAULT_JVM_OPTS="-Djava.ext.dirs="

However there is no way to use this setting with Android Studio. Also unlike what I read online , there are multiple directories

[java.ext.dirs] = /Users/aub3/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java.

I went to each directory and removed Jar files for Loggers, sl4j and others. With this I was able to get Android Studio to work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
None
  • 103
  • 3
  • 7
  • It's very like a problem with versions incompatibility To make your question more clear, provide a versions of gradle, sdk and jdk you are using. – Stanislav Nov 09 '15 at 05:19
  • @Stanislav Thanks I have updated my question – None Nov 09 '15 at 16:58
  • @StephanBranczyk I finally got gradle to assemble android project and install via installDebug tasks. I surely have JDK present. – None Nov 09 '15 at 20:35
  • Btw, use gradle wrapper when building in command line, i.e. "./gradlew build" instead of "gradle build" – Tomas Zezula Nov 09 '15 at 21:30
  • @TomasZezula Thanks for your comment I tried using gradlew, and used the wrapper. I could get it to work, via command line. See my edit. – None Nov 10 '15 at 02:03

2 Answers2

2

Check for conflicts in /Library/Java/Extensions.

In my case, I had logback-classic.jar, logback-core.jar, slf4j-api.jar and xuggle-xuggler.jar all soft-linked from some directory /usr/local/xuggler/share/java/jars/ (which I don't recall what may have installed it).

I just put these files (or links) away and now I'm able to use Gradle both from the command line and from within Android Studio. (I created a script to restore the soft-links in case my setup is broken somewhere else, but so far, I haven't run into any problems).

Joben R. Ilagan
  • 1,900
  • 1
  • 15
  • 10
0

You can Download GRADLE on website. Gradle Download. Save on any directory (example: /Users/ihojose/Documents/gradle).

  1. Open Console and add system variable.
vi ~/.profile
  1. Copy and paste the following text into the .profile file:
GRADLE_HOME=/Users/ihojose/Documents/gradle;
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin
  1. Test gradle in console
gradle -version
  1. If result if similar to this:
------------------------------------------------------------
Gradle 1.0-rc-3
------------------------------------------------------------

Gradle build time: Monday, Novenber 9, 2015 16:10:52 PM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 2.6.0 compiled on October 21 2015
Ivy: 2.2.0
JVM: 1.8.0_68 (Apple Inc. 20.6-b01-415)
OS: Mac OS X 11.0.1 x64
  1. Define ANDROID_HOME Click here for How to define ANDROID_HOME

Now you can use Android Studio.

Community
  • 1
  • 1
ihojose
  • 312
  • 2
  • 12
  • ANDROID_HOME also be defined. [How to define ANDROID_HOME](http://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x) – ihojose Nov 09 '15 at 17:34
  • Thanks, I could get gradle to work and assemble / install android project on a device using command line. But Android studio still wont work, even when specified to use local gradle distribution. – None Nov 09 '15 at 20:39
  • Strange, it worked out of the box for me - built and run an example project. Just downloaded the latest Android Studio and used a local gradle distribution (2.4). My setup: OS X 10.11.1, JDK 1.8.0_60, AS 1.4.1. Didn't have to make any extra effort. – Tomas Zezula Nov 09 '15 at 21:19
  • You can also run brew install gradle to make it available system wide. – Omer Aug 19 '19 at 22:54