Avtontom_
Avtontom_

Reputation: 405

Downgrade Android Plugin in Android Studio

I've got two workstations with Android Studio installed. The first one is having version 2.3.3, but the other one is having version 3.0. Both of them are using Gradle 3.3. The problem that I am facing is that when I create an application on the 3.0 system and then transfer it to the 2.3.3 it doesn't want to build. I am receiving

Could not resolve all dependencies for configuration ':classpath'. > Could not find com.android.tools.build:gradle:3.0.0. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar

I compared a build.gradle file created from the older version of Android Studio and from the newer version

3.0 version:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0
}
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

2.3.3:

 buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

From the 3.0 version, I removed "google()", because it was also failing.

I am new to Android Development and I would really appreciate it if you can help me to solve my problem of using one project on both of the environments.

Upvotes: 1

Views: 16636

Answers (3)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364391

Could not resolve all dependencies for configuration ':classpath'. > Could not find com.android.tools.build:gradle:3.0.0. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom

It happens because you are using the wrong repository.

If you want to use android plugin for gradle 3.x you have to use:

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

It requires also gradle v4.+ using in gradle/wrapper/gradle-wrapper.properties :

distributionUrl=\
  https\://services.gradle.org/distributions/gradle-4.1-all.zip

If you are using Android Studio 2.x you have to change the repository google() with maven { url "https://maven.google.com" }

If you want to use the android plugin for gradle 2.3.x you can use:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}

and you can use gradle v.3.3 with:

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

Of course in this case you can't use the new DSL introduced with gradle v.4.x and the plugin 3.x for example the implementation() and api() DSL.

Upvotes: 3

Sharath kumar
Sharath kumar

Reputation: 4132

If you are using android studio <3.0 then go to gradle-wrapper.properties and change the gradle from 4.1 to 3.3.

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

Go to top level gradle and change the gradle version from 3.0.0 to 2.3.3 and then it should work fine.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

If you are using android studio >3.0 then Go to gradle-wrapper.properties and change the gradle to 4.1.

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

Go to top level gradle and change the gradle version from 3.0.0 and then it should work fine.

 buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Upvotes: 1

DeKaNszn
DeKaNszn

Reputation: 2730

Android plugin 3.0 located in Google Maven Repository (google() line) and it requires new Gradle. You should update Gradle to version 4.1.

Open file gradle/wrapper/gradle-wrapper.properties and set

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

Upvotes: 1

Related Questions