org.gradle.execution.TaskSelectionException: 项目':app'中未找到任务'wrapper'。

11

几天后,我打开项目时出现了这个错误。

org.gradle.execution.TaskSelectionException: Task 'wrapper' not found in project ':app'.

我尝试了"清理项目"和"使缓存无效/重启"选项,但仍然没有运气。

项目级别的build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用程序级别的 build.gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.seeken.pomodoro"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04'
    implementation 'com.google.android.material:material:1.1.0-beta01'
    implementation 'org.greenrobot:greendao:3.2.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

如果相关的信息,我正在使用Android Studio 3.5.1。


classpath 'com.android.tools.build:gradle:3.6.0' - IntelliJ Amiya
distributionUrl=https\://services.gradle.org/distributions/?? - IntelliJ Amiya
现在它给我一个新的错误 无法找到 com.android.tools.build:gradle:。 在以下位置搜索: - Faisal Shaikh
classpath 'com.android.tools.build:gradle:3.6.1' - IntelliJ Amiya
我已经升级到3.6.1版本,但是我仍然遇到了同样的错误:Task 'wrapper' not found in project ':app'. 我也尝试过清理并重新构建项目。 - Faisal Shaikh
显示剩余4条评论
1个回答

31

我的做法是将这行代码添加到项目级别的 build.gradle 文件中(即不是最上层的 android 文件,而是内部的 app 文件):

task wrapper(type: Wrapper) {
    gradleVersion = '6.7.1'
}

Gradle版本当然取决于当前最新的版本。

接着我收到了一个不同的错误信息,关于缺少prepareKotlinBuildScriptModel,我也不得不加上这一行:

task prepareKotlinBuildScriptModel {
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接