代码之家  ›  专栏  ›  技术社区  ›  Faisal Shaikh

org.gradle.execution。TaskSelectionException:在项目“:app”中找不到任务“包装器”

  •  0
  • Faisal Shaikh  · 技术社区  · 6 年前

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

    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属性:

    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。

    0 回复  |  直到 6 年前
        1
  •  18
  •   EboMike    5 年前

    对我来说,有效的方法是将此行添加到项目级build.gradle中(即不是顶级) android 一、内部 app 一):

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

    当然,渐变版本取决于当前的最新版本。

    然后,我收到了一条关于 prepareKotlinBuildScriptModel 缺失,也必须添加这一行:

    task prepareKotlinBuildScriptModel {
    }
    
    推荐文章