【问题标题】:Android Studio :: Gradle Scripts Error Android()Android Studio :: Gradle 脚本错误 Android()
【发布时间】:2017-10-05 09:34:27
【问题描述】:

我在当前的 android 项目下使用以下脚本

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

android {
    compileSdkVersion 11
    buildToolsVersion "11.0"

    defaultConfig {
        applicationId "com.stackoverflow.answer"
        minSdkVersion 11
        targetSdkVersion 11
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

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

但后来发现这个错误信息。

如何解决?

【问题讨论】:

    标签: android android-studio gradle build compiler-errors


    【解决方案1】:

    android 块应该在包含 apply plugin: 'com.android.application' 的模块 build.gradle 中,而不是在根 build.gradle 文件中。

    例子:

    build.gradle:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.2'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
            maven { url 'https://jitpack.io' }
        }
    }
    

    模块build.gradle(可能在app文件夹内):

    apply plugin: 'com.android.application'
    
    
    android {
        compileSdkVersion 11
        buildToolsVersion "11.0"
    
        defaultConfig {
            applicationId "com.stackoverflow.answer"
            minSdkVersion 11
            targetSdkVersion 11
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 2017-07-23
      • 2018-06-06
      相关资源
      最近更新 更多