android - 在 Android Studio 中降级 Android 插件

标签 android android-studio gradle android-gradle-plugin build.gradle

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

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 文件

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()”,因为它也失败了。

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

最佳答案

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

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

如果你想为 gradle 3.x 使用 android 插件,你必须使用:

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"更改存储库 google() .com"}

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

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

并且您可以将 gradle v.3.3 用于:

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

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

关于android - 在 Android Studio 中降级 Android 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47093055/

相关文章:

java - 具有部分唤醒锁的后台重复线程的android服务

推送时出现 Git 错误 - update_ref 失败

java - 类 "android.support.v4.view.ViewPager"无法实例化

Android withText 选项不适用于 Huawei MediaPad (T1-A21L) 上的操作栏按钮

IP 地址的 Android Cookie

Android Studio文件映射问题,无法识别文件

java - 如何使用Gradle覆盖android测试路径?

android - 添加资源 “processDebugResources failed”之后

android - Android SurfaceView(canvas)如何控制重绘

android - 有什么方法可以存储图像以便用户看不到或删除它们?