111

我刚刚将我的 Android Studio 更新到 3.0 canary 1。现在我正在处理我在 Android Studio 3.0 canary 1 上的现有项目。默认情况下,我的项目中设置了gradle:3.0.0-alpha1:gradle_file。所以我将我的 gradle 版本更改为 2.2.3,现在我收到了这个错误:

错误:无法完成 Gradle 执行。

原因:您使用的 Gradle 版本 (3.3) 不支持 BuildActionExecuter 上的 forTasks() 方法。Gradle 3.5 和所有更高版本都提供了对此的支持。

我在这里附上了我的 gradle 文件

// 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:2.2.3'
        // 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
}
4

10 回答 10

196

我刚遇到同样的问题。通过更改“gradle-wrapper.properties”中的 Gradle distributionUrl 来修复它。

这是我配置的:

#Wed Mar 22 16:13:58 BRT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

更多细节

帮助迁移的官方视频 https://www.youtube.com/watch?v=oBsbI8ICYKg

另请参阅@TmTron 下面的评论

于 2017-05-26T20:14:05.847 回答
65

更改文件“gradle-wrapper.properties”。

把这条线和同步项目 -

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

这将起作用。检查最新版本services.gradle.org/distributions

更改后,从Build菜单同步项目、清理重建项目一次。

于 2017-05-30T06:11:51.300 回答
28

这发生在尝试构建调试 apk 时。

解决方案: 将 Gradle 版本更新到 3.5

导航到文件 -> 项目结构 -> 项目 -> Gradle 版本 = 3.5

这适用于 Android Studio 3.0

这是您必须进行更改的菜单图像

于 2017-11-20T21:30:34.727 回答
14

请按照以下步骤操作:

  1. 在 android studio 中打开你的项目
  2. 在 Android 菜单中,打开gradle-wrapper.properties
  3. 使用以下行更改分发 url 行

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

  1. 就是这样。立即构建您的项目。

附上截图,方便大家理解。 在此处输入图像描述

于 2017-11-06T09:22:00.317 回答
5

我通过 gradle-wrapper.properties 文件中的以下代码中的 changinf distributionUrl 解决了这个问题

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
于 2017-11-18T19:45:00.580 回答
2

一旦使用顶级 Gradle 添加这些

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha9'

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

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
于 2017-09-29T06:41:01.540 回答
1

我们有两种方法来处理它。

  1. 您可以将您的 gradle 版本从早期版本更新为 3.5 版本的产品;

  2. 或者,您可以将您的 gradle 包装器计算为 4.1 版本。

所有的方法都是有用的。

于 2017-11-24T09:01:04.070 回答
1

仅将 gradle URL 更改为

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

如下图:

在此处输入图像描述

于 2017-12-20T09:09:34.823 回答
0
  1. 打开 gradle-wrapper.properties
  2. 代替:

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

和:

distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
  1. 现在同步项目

点此了解更多

于 2018-01-14T08:26:37.187 回答
0

将此代码放在 gradle-wrapper.properties 文件中,它将与您一起使用

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
于 2018-04-18T07:26:23.990 回答