无法在当前上下文中执行任务集上的DefaultTaskContainer#register(String,Class,Action)

时间:2018-11-13 20:41:47

标签: android gradle

出现此错误:无法在当前上下文中执行任务集上的DefaultTaskContainer#register(String,Class,Action)。 IDE中未显示任何详细信息,但更新后Android Studio无法运行该应用程序。我正在使用android studio开发我的项目之一。突然发生了问题。

这是我的gradle文件: 项目级别:

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

buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        google()
        jcenter()

        // Add repository
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-core:16.0.5'

        // Check for v3.1.2 or higher
        classpath 'com.google.gms:google-services:4.2.0'

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.25.4'

        // 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"
        }
        google()
    }


}

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

应用程序级别:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.bendroidappsn.***"
        minSdkVersion 15
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 24
        versionName "APPLE"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

    }
    lintOptions {
        checkReleaseBuilds false
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-multidex-rules.pro'

        }
    }

}


ext {
    //supportLibraryVersion = '28.0.0-rc01'
    supportLibraryVersion = '28.0.0'
    playServicesVersion = '17.0.0'
}

dependencies {
    implementation "com.google.android.gms:play-services-ads:$playServicesVersion"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha07'
    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha07'
    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha07'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha07'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'

    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-firestore:17.1.2'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"


    implementation 'com.google.firebase:firebase-config:16.1.0'

    // Add dependency
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

    compile 'com.android.support:multidex:1.0.3'

}


configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {

            //if(!details.equals(com.android.support:multidex))  {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "$supportLibraryVersion"
            }

        }

    }
}

repositories {
    mavenCentral()
}

4 个答案:

答案 0 :(得分:3)

尝试设置

$pst = new DateTimeZone('America/Los_Angeles'); $last_friday = new DateTime('last friday', $pst); echo $last_friday->format('Y-m-d H:i:s'); // "2018-11-16 00:00:00"

在gradle-wrapper.properties文件中

对我有用的

答案 1 :(得分:1)

在更新到Android Studio 3.4 Canary 4之后,我遇到了这个确切的问题。 禁用即时运行即可解决此问题。

答案 2 :(得分:0)

尝试将类路径'com.android.tools.build:gradle:3.4.0-alpha02'更新为最新的版本,

答案 3 :(得分:0)

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'io.fabric'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.bendroidappsn.***"
            minSdkVersion 15
            targetSdkVersion 28
            multiDexEnabled true
            versionCode 24
            versionName "APPLE"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true

        }
        lintOptions {
            checkReleaseBuilds false
        }
        dexOptions {
            javaMaxHeapSize "4g"
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-multidex-rules.pro'

            }
        }

    }


    ext {
        //supportLibraryVersion = '28.0.0-rc01'
        supportLibraryVersion = '28.0.0'
        playServicesVersion = '17.0.0'
    }

    dependencies {
        implementation "com.google.android.gms:play-services-ads:$playServicesVersion"
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha07'
        implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha07'
        implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha07'
        implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-alpha07'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'
        implementation 'com.android.support:design:28.0.0'

        implementation 'com.google.firebase:firebase-auth:16.0.5'
        implementation 'com.android.support:support-v4:28.0.0'
        implementation 'com.android.support:support-vector-drawable:28.0.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.google.firebase:firebase-firestore:17.1.2'
        implementation 'com.android.support:gridlayout-v7:28.0.0'
        implementation 'com.android.support:cardview-v7:28.0.0'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"


        implementation 'com.google.firebase:firebase-config:16.1.0'

        // Add dependency
        implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

        compile 'com.android.support:multidex:1.0.3'

    }


    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == 'com.android.support') {

                //if(!details.equals(com.android.support:multidex))  {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "$supportLibraryVersion"
                }

            }

        }
    }

    repositories {
        mavenCentral()
    }