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

标签 android android-gradle-plugin android-build android-gradle-3.0

几天后我打开我的项目,我开始收到这个错误

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

我试过 Clean Project and Invalidate Caches/Restart选项但仍然没有运气。

项目级 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。

最佳答案

对我有用的是将此行添加到项目级 build.gradle (即不是顶级 android 一个,内部 app 一个):

task wrapper(type: Wrapper) {
    gradleVersion = '6.7.1'
}
gradle 版本当然取决于当前最新的版本。
然后我收到一条关于 prepareKotlinBuildScriptModel 的不同错误消息。丢失并且还必须添加此行:
task prepareKotlinBuildScriptModel {
}

关于android - org.gradle.execution.TaskSelectionException : Task 'wrapper' not found in project ':app' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60885949/

相关文章:

android - google-services 插件无法检测到 com.google.android.gms 或 com.google.firebase 的任何版本 - 奇怪的行为

android - Android 中 eng 和 user-debug 构建的区别

android - 添加新 API 后构建 Android AOSP 失败,因为新 API 比以前的 SDK 版本多。如何解决这个问题?

java - Asynctask 使用中的警告

java - 无法使用 CursorAdapter 子类过滤 ListView

android - Gradle同步不会自动解析带有@aar批注的Android库项目依赖项

android - 使用 URL 方案在 Facebook 应用程序中共享

android - Android Studio错误:未知主机 'service.gradle.org'

除了发布和调试之外的 Android ant 构建

android - 更改 compileSdkVersion 会影响应用程序在运行时的行为吗?