在Android Studio中降级Android插件 [英] Downgrade Android Plugin in Android Studio

查看:555
本文介绍了在Android Studio中降级Android插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个安装了Android Studio的工作站.第一个版本为2.3.3,但另一个版本为3.0.他们俩都使用Gradle 3.3.我面临的问题是,当我在3.0系统上创建应用程序然后将其传输到2.3.3时,它并不想构建.我收到了

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

无法解析配置':classpath'的所有依赖项. >找不到com.android.tools.build:gradle:3.0.0. 在以下位置搜索: 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

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

我比较了从较旧版本的Android Studio和较新版本创建的build.gradle文件

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

3.0版本:

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

从3.0版本中,我删除了"google()",因为它也失败了.

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

我是Android开发的新手,如果您能帮助我解决在两种环境下使用一个项目的问题,我将不胜感激.

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.

推荐答案

无法解析配置':classpath'的所有依赖项. >找不到com.android.tools.build:gradle:3.0.0.在以下位置搜索: https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom

发生这种情况是因为您使用了错误的存储库.

如果您想将 android插件用于gradle 3.x ,则必须使用:

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

还需要 gradle v4.+ gradle/wrapper/gradle-wrapper.properties中使用:

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

如果您使用的是 Android Studio 2.x ,则必须使用maven { url "https://maven.google.com" }

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

如果要为gradle 2.3.x使用android插件,可以使用:

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

您可以将gradle v.3.3用于:

and you can use gradle v.3.3 with:

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

当然,在这种情况下,您不能使用gradle v.4.x和插件3.x引入的新DSL,例如implementation()api() DSL.

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.

这篇关于在Android Studio中降级Android插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆