Downgrade Android Plugin in Android Studio

两盒软妹~` 提交于 2020-01-03 02:22:07

问题


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.


回答1:


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.




回答2:


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



回答3:


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()
    }
}


来源:https://stackoverflow.com/questions/47093055/downgrade-android-plugin-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!