【问题标题】:Android Studio - Error Building - Android tasks have already been createdAndroid Studio - 错误构建 - 已创建 Android 任务
【发布时间】:2015-07-06 18:58:00
【问题描述】:

构建项目时出现以下错误:

错误:(2, 0) Android 任务已创建。 调用 android.applicationVariants 时会发生这种情况, android.libraryVariants 或 android.testVariants。 一旦调用了这些方法,就不可能 继续配置模型。

根 build.gradle:

buildscript {
      repositories {
        jcenter()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
      }
}
apply plugin: 'android'

android {
    compileSdkVersion 'Google Inc.:Google APIs:19'
    buildToolsVersion '19.1.0'
    defaultConfig {
       versionCode 5
       versionName '5'
       targetSdkVersion 19
       minSdkVersion 10
       applicationId 'tsp.movil'
    }
}
dependencies {
     compile 'com.google.android.gms:play-services:7.0.0'
     compile 'com.android.support:support-v4:22.1.1'
}

应用构建.gradle:

android {
     compileSdkVersion 'Google Inc.:Google APIs:19'
     buildToolsVersion '19.1.0'
     defaultConfig {
        applicationId "tsp.movil"
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 5
        versionName '5'
     }
     buildTypes {
         release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.txt'
         }
     }
     productFlavors {
     }
}
dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/zbar.jar')
}

【问题讨论】:

    标签: android android-studio build


    【解决方案1】:

    您的顶级 build.gradle 文件应该只具有项目所有模块通用的配置。

    进行以下更改:

    build.gradle文件应该只有这段代码

    buildscript {
          repositories {
            jcenter()
          }
          dependencies {
            classpath 'com.android.tools.build:gradle:1.1.0'
          }
    }
    
    allprojects{
        repositories {
            jcenter()
          }
    }
    

    【讨论】:

    • 工作得很好,但所有项目都应该小写。
    • ya, :( 没有关于 stackoverflow 编辑器的建议,BDW 更新了答案。
    【解决方案2】:

    我遇到了类似的问题,并显示相同的错误消息。我的问题是我在包中创建了一个模块,然后在 (MacOS) Finder 中手动删除了它。

    问题是我忘了从settings.gradle 文件中删除include ::myModule 行。

    【讨论】:

      【解决方案3】:

      看看这个: How to define common android properties for all modules using gradle 第三条评论说已经创建了 Android 任务。调用 android.applicationVariants、android.libraryVariants 或 android.testVariants 时会发生这种情况。一旦调用了这些方法,就无法继续配置模型。

      【讨论】:

        猜你喜欢
        • 2014-05-08
        • 1970-01-01
        • 2022-09-24
        • 2015-05-10
        • 2018-09-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多