【问题标题】:build.gradle file could not compilebuild.gradle 文件无法编译
【发布时间】:2021-05-07 13:20:13
【问题描述】:

运行项目时出现此错误:

无法编译构建文件'H:\StartActivity\build.gradle'

启动失败: build file 'H:\StartActivity\build.gradle': 28: 在 plugins {} 块之前只允许 buildscript {} 和其他 plugins {} 脚本块,不允许其他语句

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        ext.kotlin_version = "1.5.0-release-764"
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:4.2.0"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter() // Warning: this repository is going to shut down soon
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    plugins {
        id 'org.jetbrains.kotlin.jvm' version '1.5.0-release-764'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    }
    compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }

【问题讨论】:

标签: android-gradle-plugin


【解决方案1】:
buildscript {
    ext.kotlin_version = "1.5.0"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

将 ext.kotlin_version 更改为 1.5.0 正在工作 :)

【讨论】:

    【解决方案2】:

    你应该在 allprojects{...} 之前移动 plugins{...}

        // Top-level build file where you can add configuration options common to all sub-projects/modules.
        buildscript {
            ext.kotlin_version = "1.5.0-release-764"
            repositories {
                google()
                mavenCentral()
            }
            dependencies {
                classpath "com.android.tools.build:gradle:4.2.0"
                classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        
                // NOTE: Do not place your application dependencies here; they belong
                // in the individual module build.gradle files
            }
        }
    
        plugins {
            id 'org.jetbrains.kotlin.jvm' version '1.5.0-release-764'
        }
        
        allprojects {
            repositories {
                google()
                mavenCentral()
                jcenter() // Warning: this repository is going to shut down soon
            }
        }
        
    ....
    
    

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 2021-11-19
      • 2022-07-18
      • 2021-01-25
      • 2013-11-24
      • 2012-09-04
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多