4

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:

  1. Invalidate Cache and Restart
  2. Changing the distributionURL in gradle-wrapper/properties to 2.5 etc.
  3. 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 }
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
Maddy
  • 89
  • 1
  • 1
  • 6

5 Answers5

7

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
iminiki
  • 2,549
  • 12
  • 35
  • 45
kulsin
  • 398
  • 4
  • 18
2

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.

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • This didn't work. Sorry I thought it had earlier. I downloaded Android Studio again, started a new project, and made your suggested changes. The first change is in gradle-wrapper.properties I guess, under the application folder. The second is in build.gradle. The new error is "Error:Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.8-all.zip'." – Maddy Jan 10 '16 at 17:56
  • change in `classpath` version of Gradle to `1.3.0` and stay with `gradle-2.4-all.zip` - if upgrading is not allowed try to downgrade to `1.3` version – piotrek1543 Jan 10 '16 at 19:06
  • Anyone have any solutions to this issue? I am too facing same issue while importing project into eclipse. I am using java 9 – SachinB Mar 12 '18 at 18:49
1

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
sib10
  • 1,104
  • 1
  • 9
  • 15
  • This did not work for me on a fresh installation of Studio 3.3 on Ubuntu. Both /opt/android-studio/gradle and ~/AndroidStudioProjects/myproject/gradle were already owned by me with permissions 775, and when I chmod -R 777 both of them and restart studio I have the same issue. – andrew lorien Jan 19 '19 at 02:56
  • +1 This was it! Thanks. But now I want to know in which user group `Intellij` itself falls. Why was `Intellij` being revoked access to `/opt/gradle`? In which user group does it normally belong? – Mike Sep 10 '20 at 22:00
0

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.

AndreGraveler
  • 437
  • 6
  • 12
  • Hi, (especially if you are building a LibGdx project), after following the above instructions, you may need to run your gradle builds to that it can build the necessary files for your project. I usually import my project in android studio and use the gradle sync option. However, you can run gradle wrapper of your project on the command line as well. – AndreGraveler Mar 27 '19 at 12:56
0

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

mylittleswift
  • 320
  • 2
  • 8