Android Studio - 错误构建 - Android 任务已经创建 [英] Android Studio - Error Building - Android tasks have already been created

查看:40
本文介绍了Android Studio - 错误构建 - Android 任务已经创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Getting the following error when building the project:

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

Error:(2, 0) Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

root build.gradle:

Root 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:

App build.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')
}

推荐答案

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

Your Top Level build.gradle file should only have the configuration common for all modules of your project.

进行以下更改:

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

Root build.gradle file should have only this piece of code

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

allprojects{
    repositories {
        jcenter()
      }
}

这篇关于Android Studio - 错误构建 - Android 任务已经创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆